How do I get the current UTC offset (as in time zone, but just the UTC offset of the current moment)?
I need an answer like "+02:00".
How do I get the current UTC offset (as in time zone, but just the UTC offset of the current moment)?
I need an answer like "+02:00".
Since C++11 you can use chrono and std::put_time:
This produces the following output:
There are two parts to this question:
boost::posix_time::time_duration
time_duration
as specifiedApparently, getting the local time zone is not exposed very well in a widely implemented API. We can, however, get it by taking the difference of a moment relative to UTC and the same moment relative to the current time zone, like this:
Formatting the offset as specified is just a matter of imbuing the right
time_facet
:Now,
get_utc_offset_string()
will yield the desired result.