linux C打印时间

1.输出unix时间戳,和本地时间 

#include<time.h>
#include<stdio.h>    
  
void main()   
{   
time_t now;     
struct tm *timenow;     
time(&now);   //获取unix时间戳
printf("now:%llu\n",now);  
  
timenow = localtime(&now);   //将unix时间戳,转化为本地时间    
  
printf("Local time is %s/n",asctime(timenow));   //asctime函数把时间转换成字符,通过printf()函数输出    
}   

 

posted @ 2021-01-08 18:08  疾风泣影  阅读(1545)  评论(0编辑  收藏  举报