1

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?

ivan.ukr
  • 2,853
  • 1
  • 23
  • 41

2 Answers2

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