【代码片段】时间戳

#include "g_time.h"

#include 
#include 
#include 

void get_timestamp(char * const str){                                                                    
    struct timeval tv; 
    struct tm tm_time;
    gettimeofday(&tv, NULL);
    gmtime_r(&tv.tv_sec, &tm_time);

    long mseconds, useconds;
    mseconds = tv.tv_usec / 1000;
    useconds = tv.tv_usec % 1000;
    sprintf(str, "%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);
}

 

你可能感兴趣的:(时间,后端)