学习备忘--获取当前日期时间(精确到毫秒)

#include 
#include 
#include 
#include 
using namespace std;
typedef char * PCHAR;
void Now(PCHAR buff);
int main()
{
    char buff[128];
    Now(buff);
    cout << buff << endl;
    return 0;
}
void Now(PCHAR buff)
{
    struct timeb tp;
    struct tm *tm;
    ftime(&tp);
    tm = localtime(&tp.time);
    sprintf(buff, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d.%.3d",
            1900+ tm->tm_year,
            1 + tm->tm_mon,
            tm->tm_yday,
            tm->tm_hour,
            tm->tm_min,
            tm->tm_sec,
            tp.millitm);
}
欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧! 158427611 

你可能感兴趣的:(struct,include)