【发布时间】:2010-01-25 03:41:44
【问题描述】:
我有以下时间:
2010-01-25 03:13:34.384 - GMT Time Zone
2010-01-25 11:13:34.384 - My Local
我希望以毫秒为单位转换为时间戳。但是,由于我只从调用者那里获取本地时间字符串 “2010-01-25 11:13:34.384”
如果我这样做:
// ts is "2010-01-25 11:13:34.384" (My Local)
boost::posix_time::ptime t(boost::posix_time::time_from_string(ts));
boost::posix_time::ptime end(boost::gregorian::date(1970,1,1));
boost::posix_time::time_duration dur = t - end;
// epoch is 1264418014384
// 2010-01-25 11:13:34.384 (GMT) -- But I want 2010-01-25 03:13:34.384
// 2010-01-25 19:13:34.384 (My Local) -- But I want 2010-01-25 11:13:34.384
long long epoch = dur.total_milliseconds();
有没有办法告诉 boost::posix_time,它接收到的 ts 字符串属于 My Local timezone?
【问题讨论】: