【问题标题】:QT unixtimestamp conversion not print GMT timeQT unixtimestamp 转换不打印 GMT 时间
【发布时间】:2020-05-03 09:51:11
【问题描述】:

我有 unixtimestamp 1579106713 代表 1/15/2020 16:45:13,我需要在 Qt 中转换这个时间,我使用了代码但得到了不同的值

 int unixTimeTmp = 1579106713; // 1/15/2020 16:45:13
 QDateTime timestampq;
 timestampq.setTime_t(unixTimeTmp);
 qDebug() << timestampq.toString();

给出输出

Wed Jan 15 11:45:13 2020 // expect Wed Jan 15 16:15:33 2020

当我在这里查看https://www.epochconverter.com 时,我发现我必须获取 GMT 输出,但不知道如何使用 Qt

【问题讨论】:

    标签: qt datetime gmt


    【解决方案1】:

    您需要将 timespec 设置为 Qt::UTC。像这样:

    int unixTimeTmp = 1579106713; // 1/15/2020 16:45:13
    QDateTime timestampq;
    timestampq.setTime_t(unixTimeTmp);
    timestampq.setTimeSpec(Qt::UTC);
    qDebug() << timestampq.toString();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-02
      • 2020-07-01
      • 2020-01-30
      • 2018-06-28
      • 2017-08-26
      • 2012-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多