定义于头文件
<ctime>
|
||
std::tm* gmtime( const std::time_t* time );
|
||
将给定作为 std::time_t 值的从纪元起时间转换为以协调世界时( UTC )表达的日历时间。
目录 |
time | - | 指向要转换的 time_t 对象的指针 |
成功时为指向静态内部 std::tm 对象的指针,否则为 NULL 。该结构体可能在 std::gmtime 、 std::localtime 和 std::ctime 之间共享,并可能在每次调用时被覆盖。
此函数可能不是线程安全的。
POSIX 要求若此函数因参数过大而失败,则设置 errno 为 EOVERFLOW 。
#include <iostream> #include <iomanip> #include <ctime> int main() { std::time_t t = std::time(nullptr); std::cout << "UTC: " << std::put_time(std::gmtime(&t), "%c %Z") << '\n'; std::cout << "local: " << std::put_time(std::localtime(&t), "%c %Z") << '\n'; }
输出:
UTC: Wed Dec 28 11:44:28 2011 GMT local: Wed Dec 28 06:44:28 2011 EST
转换纪元起时间到表示为本地时间的日历时间 (函数) |
|
gmtime的 C 文档
|