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);
}
上一篇: 避免回调地狱的解决方案 async/await:用同步的方式去写异步代码
下一篇: js时间的理解