09.打印時間,單位是毫秒

內容來自下面文章
https://blog.csdn.net/xinhua0910/article/details/19046621

#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>
 
char*   log_Time(void)
{
        struct  tm      *ptm;
        struct  timeb   stTimeb;
        static  char    szTime[19];
 
        ftime(&stTimeb);
        ptm = localtime(&stTimeb.time);
        sprintf(szTime, "%02d-%02d %02d:%02d:%02d.%03d",
                ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, stTimeb.millitm);
        szTime[18] = 0;
        return szTime;
}
 
int main()
{
        printf("[%s]\n", log_Time());
 
        return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章