#include <stdio.h> #include <time.h> #include <sys/time.h> void sysLocalTime() { time_t timesec; struct tm *p; time(×ec); p = localtime(×ec); printf("%d%d%d%d%d%d ", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec); } void sysUsecTime() { struct timeval tv; struct timezone tz; struct tm *p; gettimeofday(&tv, &tz); printf("tv_sec:%ld ",tv.tv_sec); printf("tv_usec:%ld ",tv.tv_usec); printf("tz_minuteswest:%d ",tz.tz_minuteswest); printf("tz_dsttime:%d ",tz.tz_dsttime); p = localtime(&tv.tv_sec); printf("time_now:%d%d%d%d%d%d.%ld ", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec); } int main(void) { sysLocalTime(); printf("============gettimeofday============== "); sysUsecTime(); return 0; }
Linux获取系统当前时间(精确到毫秒)
免责声明:文章转载自《Linux获取系统当前时间(精确到毫秒)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇# vue 使用 cesium 接入 gltf 模型taro 开发注意点下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=