欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux时间戳生成

程序员文章站 2024-01-28 09:21:22
...
#include "g_time.h"

#include <stdio.h>
#include <time.h>
#include <sys/time.h>

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);
}

 

相关标签: 时间 Linux