时间戳

 

#include <time.h>                                                                                                                                            
#include <sys/time.h>
#include <stdio.h>
 
char * getTimestamp()
{    
    struct timeval tv; 
    struct tm tm_time;
    gettimeofday(&tv, NULL);
    gmtime_r(&tv.tv_sec, &tm_time);
 
    static char timestamp[32];
    long mseconds, useconds;
    mseconds = tv.tv_usec / 1000;
    useconds = tv.tv_usec % 1000;
    sprintf(timestamp, "%d/%d/%d %d:%d:%d:%ld:%ld", \
            tm_time.tm_year +1900, tm_time.tm_mon, tm_time.tm_mday, \
            tm_time.tm_hour +8, tm_time.tm_min, tm_time.tm_sec, \
            mseconds, useconds);

    return timestamp;
}

posted on 2019-12-28 19:22  sermatec江  阅读(144)  评论(0编辑  收藏  举报