gmtime():获取格林威治(伦敦)的时间,已经转换成其他国家的时间(时差)
#include <iostream>
#include <ctime>
using namespace std;
// 定义宏, 即: BST 表示常量 1, CCT 表示常量 8,
// 如 #define CONST (a+b+c) 表示用 CONST 来表示 a+b+c 式子, 作用是提高代码的通用性
#define BST 1
#define CCT 8
int main()
{
time_t rawtime; // 声明 time_t 变量
struct tm info; // 声明 tm 结构体
time(&rawtime); // 获取系统时间
gmtime_s(&info, &rawtime); // 获取 GMT(格林威治,即伦敦) 时间
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);
system("pause");
return 0;
}
输出:


浙公网安备 33010602011771号