获取时间函数

#include <stdio.h>
#include <time.h>
 
#define BST (+1)
#define CCT (+8)
 
int main ()
{
 
   time_t rawtime;
   struct tm *info;
 
   time(&rawtime);
   /* 获取 GMT 时间 */
   info = gmtime(&rawtime );
   
   printf("当前的世界时钟:\n");
   printf("伦敦:%2d:%02d\n", (info->tm_hour+BST)%24, info->tm_min);
   printf("中国:%2d:%02d\n", (info->tm_hour+CCT)%24, info->tm_min);
     char outbuf[72] = {0};
   //snprintf(outbuf, 71, "D:%d+08\'00\'", 1900 + info->tm_year);
   snprintf(outbuf, 71, "D:%d+08'00'", 1900 + info->tm_year);	//等效
   printf("outbuf: %s\n", outbuf);
   return(0);
}

 

上一篇:守护进程写日志


下一篇:linux 中 gmtime和 localtime区别