I need to get time zone offset from a time zone name string expressed exactly like this "Pacific/Auckland". I know that boost::date_time would do the job, but I need to do it without that. Manipulations with TZ variable are also not allowed. Anyone have idea how to accomplish this task in such a way?
Asked
Active
Viewed 1,354 times
1
-
Are you working in Windows? – Rahul Tripathi Oct 23 '15 at 07:52
-
You need to find, build, buy, borrow, or steal a database of timezone names. Try the find option first. Perhaps there's one on your linux machine. – n. m. could be an AI Oct 23 '15 at 07:53
-
@Rahul Tripathi: yes, currently doing things in Windows – ivan.ukr Oct 23 '15 at 07:56
-
@n.m thanks :))) I will try. Actually there is public timezone DB exists for example here https://www.iana.org/time-zones – ivan.ukr Oct 23 '15 at 07:59
-
@ivan.ukr:- Did you check this: [How to get the current time zone?](http://stackoverflow.com/questions/2136970/how-to-get-the-current-time-zone) – Rahul Tripathi Oct 23 '15 at 07:59
-
@Rahul Tripathi: I need a different time zone, not current. With current time zone everything is very clear. – ivan.ukr Oct 23 '15 at 08:01
-
@Rahul Tripathi: Doesn't work for me. Uses either boost or TZ variable manipulation. – ivan.ukr Oct 23 '15 at 08:07
2 Answers
2
I know this is an old question, but I just had to write the code list the known timezones, so I'm sharing it here.
#include <date/tz.h>
const date::tzdb & tzdb = date::get_tzdb();
for (const date::time_zone & tz: tzdb.zones) {
cout << "TZ: " << tz.name() << endl;
}
This uses Howard Hinnants Date Library, and you'll need to compile in the tz.cpp file and have a path to the includes.
With C++20, the library is part of the standard, but I'm still on C++17.

Joseph Larson
- 8,530
- 1
- 19
- 36
1
Take a look at Howard Hinnant's parser for the Time Zone Database. He also provides a very good date/time library.

Jens
- 9,058
- 2
- 26
- 43
-
Thanks, I will take a look. This may be really what I am looking for. – ivan.ukr Oct 23 '15 at 07:57
-