tim*_*day 12 c++ timezone debian boost boost-date-time
如果我date +%H-%M-%S
在命令行(Debian/Lenny)上做的话,我会得到一个用户友好的(不是UTC,而不是DST-less,正常人在他们的手表上的时间)打印时间.
获得同样东西的最简单方法是boost::date_time
什么?
如果我这样做:
std::ostringstream msg;
boost::local_time::local_date_time t =
boost::local_time::local_sec_clock::local_time(
boost::local_time::time_zone_ptr()
);
boost::local_time::local_time_facet* lf(
new boost::local_time::local_time_facet("%H-%M-%S")
);
msg.imbue(std::locale(msg.getloc(),lf));
msg << t;
Run Code Online (Sandbox Code Playgroud)
然后msg.str()
比我想要的时间早一个小时.我不确定这是因为它显示UTC或本地时区没有DST校正时间(我在英国).
修改上述内容以获得DST更正的本地时区时间的最简单方法是什么?我知道它涉及boost::date_time:: c_local_adjustor
但无法从示例中弄清楚.
tim*_*day 17
这就是我想要的:
namespace pt = boost::posix_time;
std::ostringstream msg;
const pt::ptime now = pt::second_clock::local_time();
pt::time_facet*const f = new pt::time_facet("%H-%M-%S");
msg.imbue(std::locale(msg.getloc(),f));
msg << now;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
24294 次 |
最近记录: |