【发布时间】:2016-04-22 16:55:14
【问题描述】:
例如我有数字(以毫秒为单位)1439467747492,我需要将其转换为数据格式。数字将返回: 格林威治标准时间 2015 年 8 月 13 日星期四 12:09:07。
是一个函数来做到这一点还是我需要一个特定的代码来做到这一点?
谢谢!
【问题讨论】:
例如我有数字(以毫秒为单位)1439467747492,我需要将其转换为数据格式。数字将返回: 格林威治标准时间 2015 年 8 月 13 日星期四 12:09:07。
是一个函数来做到这一点还是我需要一个特定的代码来做到这一点?
谢谢!
【问题讨论】:
#include <time.h>
#include <iostream>
int main() {
time_t a = 1439467747492 / 1000; // or 1439467747
std::cout << "The time is " << ctime(&a);
}
【讨论】:
您可以使用<ctime> 标头。
文档here。
示例代码(从文档复制)
#include <ctime>
#include <iostream>
int main()
{
std::time_t test = 1439467747492;
std::cout << std::ctime(&test);
}
输出:
Sat Dec 1 08:04:52 47584
【讨论】: