时间戳

#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;
}
原文地址:https://www.cnblogs.com/orejia/p/12068373.html