Boost logo

Boost Users :

Subject: [Boost-users] [date time] Querying current time zone settings.
From: Rodolfo Federico Gamarra (rgamarra_at_[hidden])
Date: 2009-01-23 10:54:22


Hi all!

I'm using

boost::posix_time::second_clock::local_time()

to retrieve my current local time, and then using operator<< to stream
the resulting ptime.

I'd like to add to the output my local time zone (as configured in the
underlying OS). Be it just a time difference or (better) a region
(like "America/New_York").

I have been looking but didn't find how to to it. The class ptime
doesn't include the time zone; and all the other examples I've seen in
to docs work with an explicitly used time zone in the code. For
example:

time_zone_ptr zone( new posix_time_zone("MST-07") );
local_date_time ldt = local_sec_clock::local_time(zone);

And, for instance, in the docs about I/O it can be seen "%q ISO
time zone (output only). This flag is ignored when using the
time_facet with a ptime.". There's also a
boost::date_time::c_local_adjustor (which warns about "This class
assumes that timezone settings of the machine are correct. This can
be a very dangerous assumption."), but doesn't help me much.

By now, I can use (also)

boost::posix_time::second_clock::universal_time()

to infer my time zone.

Is there any alternative to this?

Thanks a lot.

--
Rodolfo Federico Gamarra

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net