【问题标题】:Transforming Unix Timestamp in milliseconds to a normal date [duplicate]以毫秒为单位将Unix时间戳转换为正常日期[重复]
【发布时间】:2016-04-22 16:55:14
【问题描述】:

例如我有数字(以毫秒为单位)1439467747492,我需要将其转换为数据格式。数字将返回: 格林威治标准时间 2015 年 8 月 13 日星期四 12:09:07。

是一个函数来做到这一点还是我需要一个特定的代码来做到这一点?

谢谢!

【问题讨论】:

  • 也许你需要this。已回复here
  • 这些毫秒时间戳的参考点是什么?从纪元开始?

标签: c++ datetime timestamp


【解决方案1】:
#include <time.h>
#include <iostream>

int main() {
    time_t a = 1439467747492 / 1000; // or 1439467747
    std::cout << "The time is " << ctime(&a);
}

【讨论】:

    【解决方案2】:

    您可以使用&lt;ctime&gt; 标头。

    文档here

    示例代码(从文档复制)

    #include <ctime>
    #include <iostream>
    
    int main()
    {
        std::time_t test = 1439467747492;
        std::cout << std::ctime(&test);
    }
    

    输出:

    Sat Dec  1 08:04:52 47584
    

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 1970-01-01
      • 2020-06-24
      • 2017-05-28
      • 1970-01-01
      • 2016-04-25
      • 2015-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多