输出boost :: chrono :: system_clock :: time_point作为相对于UTC的本地时间

时间:2015-05-08 17:45:28

标签: c++ boost chrono

我正在尝试将boost :: chrono :: system_clock :: time_point输出到文件流,以便显示本地时间,但与UTC时间不同,例如:

  

2015-05-08 11:49:07.890992700 -0400

基于documentation,可以通过将time_fmt操纵器与本地时区一起使用来实现:

std::ofstream file("MyFile.txt");
boost::chrono::system_clock::time_point timePoint = boost::chrono::system_clock::now();
file << boost::chrono::time_fmt(boost::chrono::timezone::local)
     << timePoint;

然而,我得到的结果是:

  

2015-05-08 11:49:07.890992700东部夏令时

基本上,我希望将“Eastern Daylight Time”时区字符串替换为UTC的“-0400”时区差异。我猜测结果可能取决于系统本地设置。无论系统设置如何,我有没有办法实现这一目标?

1 个答案:

答案 0 :(得分:0)

AFAIK + HHMM格式称为POSIX时区。

FWIW我想你的意思是if (wizardPrivate->isVistaThemeEnabled(QVistaHelper::VistaBasic)) { if (window()->isActiveWindow()) painter.setPen(QPen(QBrush(QColor(169, 191, 214)), 0)); // ### hardcoded for now else painter.setPen(QPen(QBrush(QColor(182, 193, 204)), 0)); // ### hardcoded for now painter.drawLine(0, 0, width(), 0); } ,而且我的系统上有一些测试运行:

system_clock::now()

所以它似乎确实依赖于平台和潜在的配置(但我不认为它取决于选项的区域设置)。

另见 Live On Coliru

$ TZ='Asia/Kathmandu' ./test
2015-05-10 04:46:40.655817854 +0545

$ TZ='America/Detroit' ./test
2015-05-09 18:59:57.022323975 -0400

[1] 我用//#include <boost/chrono/chrono_io.hpp> #include <boost/chrono/time_point.hpp> #include <boost/chrono/io/time_point_io.hpp> #include <boost/chrono/chrono.hpp> #include <iostream> int main() { boost::chrono::system_clock::time_point timePoint = boost::chrono::system_clock::now(); std::cout << boost::chrono::time_fmt(boost::chrono::timezone::local) << timePoint << "\n"; } 计算了这个:

tzselect