As far as I understand wrong time
means that it is has one hour difference to expected, i.e. -4 hours instead of expected -5 hours. If yes, then the problem is that the us_std
type is pointed as the last parameter of the local_adjustor
declaration. If to specify no_dst
instead of the use_dst
. The code works as expatiated and the difference is -5 hours. The following code demonstrates it (link to online compiled version)
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/local_time_adjustor.hpp>
#include <iostream>
int main(void) {
const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
const boost::posix_time::ptime adjUSDST = boost::date_time::local_adjustor<boost::posix_time::ptime, -5, boost::posix_time::us_dst>::utc_to_local(now);
const boost::posix_time::ptime adjNODST = boost::date_time::local_adjustor<boost::posix_time::ptime, -5, boost::posix_time::no_dst>::utc_to_local(now);
std::cout << "now: " << now << std::endl;
std::cout << "adjUSDST: " << adjUSDST << std::endl;
std::cout << "adjNODST: " << adjNODST << std::endl;
return 0;
}