c++ - Convert Boost Ptime To EST UTC-5:00 -
i using following code current date time (mountain time)
const boost::posix_time::ptime = boost::posix_time::second_clock::local_time(); //in mountain time = 2013-apr-08 20:44:22
now using following method conversion
ptime feedconnector::mountainttoeasternconversion(ptime colotime) { return boost::date_time::local_adjustor <ptime, -5, us_dst>::utc_to_local(colotime); }
//this function suppose give me time in newyork (east standard time) , getting
2013-apr-08 16:44:22
thsi time wrong suggestion going wrong ?
as far understand wrong time
means has 1 hour difference expected, i.e. -4 hours instead of expected -5 hours. if yes, problem us_std
type pointed last parameter of local_adjustor
declaration. if specify no_dst
instead of use_dst
. code works expatiated , difference -5 hours. following code demonstrates (link 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 = 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: " << << std::endl; std::cout << "adjusdst: " << adjusdst << std::endl; std::cout << "adjnodst: " << adjnodst << std::endl; return 0; }
Comments
Post a Comment