- time_t t; //秒时间
- tm* local; //本地时间
- tm* gmt; //格林威治时间
- char buf[128]= {0};
- t = time(NULL); //获取目前秒时间
- local = localtime(&t); //转为本地时间
- strftime(buf, 64, "%Y-%m-%d %H:%M:%S", local);
- std::cout << buf << std::endl;
- gmt = gmtime(&t);//转为格林威治时间
- strftime(buf, 64, "%Y-%m-%d %H:%M:%S", gmt);
-
std::cout << buf << std::endl;