0

I am living in the Netherlands, when I run this code:

boost::local_time::local_date_time t = boost::local_time::local_sec_clock::local_time(boost::local_time::time_zone_ptr());

std::cout << "\nDate Time: " << t.to_string() ;

The "Date Time" returned is one hour behind. It is UTC but it should be GMT+1 or UTC+1 for my current system date time!

What should I change to the boost::local_time to get the system date time.

Thanks in advance.

olidev
  • 20,058
  • 51
  • 133
  • 197
  • If you want your current system time, use posix_time, not local_time. See http://stackoverflow.com/questions/2612938/simplest-way-to-get-current-time-in-current-timezone-using-boostdate-time and http://stackoverflow.com/questions/2492775/get-local-time-with-boost/2493977. – Éric Malenfant Nov 16 '10 at 14:10

2 Answers2

2

boost::local_time::time_zone_ptr zone_GMT1(new boost::local_time::posix_time_zone("GMT+1"));

boost::local_time::local_date_time t = boost::local_time::local_sec_clock::local_time(zone_GMT1);

I found out to use the timeZone.

It works fine for me

Thanks!

olidev
  • 20,058
  • 51
  • 133
  • 197
0

Maybe you have to enable daylight savings time calculation, by giving an additional parameter set to true (the DST flag), see http://www.boost.org/doc/libs/1_38_0/doc/html/date_time/local_time.html#id3051627

Anselm Eickhoff
  • 589
  • 2
  • 5
  • 14