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”.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are two parts to this question:
boost::posix_time::time_durationtime_durationas 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.