#include <time.h>
struct tm *gmtime( const time_t *time );
函数返回给定的统一世界时间(通常是格林威治时间),如果系统不支持统一世界时间系统返回 NULL。
#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);
return(0);
}输出结果:
当前的世界时钟: 伦敦:16:20 中国:23:20