Cxxtools offers a class for handling time zones. The main task is to convert a datetime from UTC to a time zone or back.
Cxxtools has already a class cxxtools:DateTime, which represents obviously a date and a time. From that 2 classes LocalDateTime and UtcDateTime are derived, which do not add any functionality but offsers a little safety. In addition a class TzDateTime, which is derived from LocalDateTime adds the time zone information to the class.
The class cxxtools cxxtools::Tz uses the system time zone database to convert the datetimes between UTC and time zone.
The default constructor of Tz initializes it with the system time zone. Optionally a different time zone can be passed as a parameter.
The most important methods in Tz are toLocal and toUtc.
A very simple example is here:
cxxtools::Tz myTimezone;
cxxtools::Tz nauruTimezone("Pacific/Nauru");
auto localtime = cxxtools::DateTime::localtime();
std::cout << "current local time " << localtime.toString() << std::endl;
auto utctime = myTimezone.toUtc(localtime);
std::cout << "current utc time " << utctime.toString() << std::endl;
auto naurutime = nauruTimezone.toLocal(utctime);
std::cuot << "time at nauru: " << naurutime.toString() << std::endl;