Simplest way to get current time in current timezone using boost::date_time ?

Posted by timday on Stack Overflow See other posts from Stack Overflow or by timday
Published on 2010-04-10T10:00:23Z Indexed on 2010/04/10 10:03 UTC
Read the original article Hit count: 1521

Filed under:
|
|
|
|

If I do date +%H-%M-%S on the commandline (Debian/Lenny), I get a user-friendly (not UTC, not DST-less, the time a normal person has on their wristwatch) time printed.

What's the simplest way to obtain the same thing with boost::date_time ?

If I do this:

std::ostringstream msg;

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

boost::local_time::local_time_facet* lf(
  new boost::local_time::local_time_facet("%H-%M-%S")
);

msg.imbue(std::locale(msg.getloc(),lf));
msg << t;

Then msg.str() is an hour earlier than the time I want to see. I'm not sure whether this is because it's showing UTC or local timezone time without a DST correction (I'm in the UK).

What's the simplest way to modify the above to yield the DST corrected local timezone time ? I have an idea it involves boost::date_time:: c_local_adjustor but can't figure it out from the examples.

© Stack Overflow or respective owner

Related posts about boost

Related posts about c++