Reputation: 13892
I'm trying to convert a UTC time to a custom time zone. I've read a lot of questions about it here and there but they all seem to do the opposite, or to use a time adjustor where you can't set the timezone. So far here what I've managed to do:
boost::local_time::time_zone_ptr time_zone(new boost::local_time::posix_time_zone("EST5EDT,M3.2.0,M11.1.0"));
boost::posix_time::ptime const now(boost::gregorian::date(2004,11,5), boost::posix_time::hours(10));
boost::local_time::local_date_time const ny(now, time_zone );
//
ny.utc_time().time_of_day(); // Expected: 10:00 Actual: 10:00
ny.local_time().time_of_day(); // Expected: 04:00 Actual: 16:00
I want ny.local_time() to show be 04:00, because when UTC time is 10:00, it's 4:00 in new york.
Can anyone suggest the right way to do it ?
Upvotes: 0
Views: 2160
Reputation: 254431
The boost library seems to interpret the "offset" as the amount to add to UTC to get the local time; while the standard POSIX convention is the other way round. Change it to
"EST-5EDT,M3.2.0,M11.1.0"
^
Upvotes: 2