Linux获取系统当前时间(精确到毫秒)

原文地址::https://blog.csdn.net/weixin_34179762/article/details/90655525

相关文章

1、Linux获取系统时间,精确到毫秒----https://blog.csdn.net/tajon1226/article/details/103201935

2、Linux获取系统当前时间(精确到毫秒)----https://www.cnblogs.com/chars/p/4975460.html

3、Linux获取系统当前时间(精确到毫秒)----https://www.cnblogs.com/catgatp/p/6431187.html

4、linux获取时间,精确到微秒usec----https://blog.csdn.net/qq_33195791/article/details/81812445

5、获取系统时间,精确到微秒----https://blog.csdn.net/weixin_33690963/article/details/92391207

 

  1. #include <stdio.h>

  2. #include <time.h>

  3. #include <sys/time.h>

  4.  
  5. void sysLocalTime(void)

  6. {

  7. time_t timesec;

  8. struct tm *t;

  9.  
  10. time(×ec);

  11. t = localtime(×ec);

  12.  
  13. printf("%d-%d-%d %d:%d:%d\n", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);

  14. }

  15.  
  16. void sysUsecTime(void)

  17. {

  18. struct timeval tv;

  19. struct timezone tz;

  20. struct tm *t;

  21.  
  22. gettimeofday(&tv, &tz);

  23. printf("tv_sec:%ld\n",tv.tv_sec);

  24. printf("tv_usec:%ld\n",tv.tv_usec);

  25. printf("tz_minuteswest:%d\n",tz.tz_minuteswest);

  26. printf("tz_dsttime:%d\n",tz.tz_dsttime);

  27.  
  28. t = localtime(&tv.tv_sec);

  29. printf("time_now:%d-%d-%d %d:%d:%d.%ld\n", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);

  30. }

  31.  
  32. int main(void)

  33. {

  34. sysLocalTime();

  35. sysUsecTime();

  36.  
  37. return 0;

  38. }

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值