我有以下时间:特定时区中的boost ::了posix_time ::的ptime
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();
有没有办法告诉升压: :posix_time,它收到的ts字符串是否属于我的本地时区?
我可以知道你怎么了获取当前时区? – 2010-01-26 01:12:28
您将其保存在TZ环境变量中。 – 2010-01-26 02:20:05