std::gmtime

定义于头文件 <ctime>
std::tm* gmtime( const std::time_t* time );

将给定作为 std::time_t 值的从纪元起时间转换为以协调世界时( UTC )表达的日历时间。

目录

参数

time - 指向要转换的 time_t 对象的指针

返回值

成功时为指向静态内部 std::tm 对象的指针,否则为 NULL 。该结构体可能在 std::gmtimestd::localtimestd::ctime 之间共享,并可能在每次调用时被覆盖。

注意

此函数可能不是线程安全的。

POSIX 要求若此函数因参数过大而失败,则设置 errnoEOVERFLOW

示例

#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

参阅

转换纪元起时间到表示为本地时间的日历时间
(函数)
gmtimeC 文档

版本历史

  • (当前 | 先前 2017年10月11日 (三) 05:48Fruderica讨论 | 贡献. . (1,289字节) (-742). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 16:39P12bot讨论 | 贡献 . . (2,031字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 07:20P12bot讨论 | 贡献 . . (2,031字节) (-40). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 15:50P12bot讨论 | 贡献 . . (2,071字节) (+135). . (r2.7.3) (机器人添加:de, en, es, it, pt, ru 去除:zh) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 09:50P12讨论 | 贡献 . . (1,936字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (1,936字节) (-47). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 13:14P12讨论 | 贡献 . . (1,983字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,983字节) (+1,290). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年5月4日 (五) 11:17P12bot讨论 | 贡献 . . (693字节) (+82). . (r2.7.3) (机器人添加:en:cpp/chrono/c/gmtime, fr:cpp/chrono/c/gmtime, ja:cpp/chrono/c/gmtime (撤销)
  • 当前 | 先前 2012年5月1日 (二) 03:36P12讨论 | 贡献 . . (611字节) (0). . (1个修订: Import from Dokuwiki) (撤销)
  • 当前 | 先前) 2012年5月1日 (二) 03:36P12讨论 | 贡献. . (611字节) (+611). . (Import from dokuwiki)