c++ - Convert timestamp in milliseconds into a timezone in boost -


i have client java library parses iso timestamp timezone using joda-time library , returns long value (milliseconds since epoch in utc). need develop server-side framework (in c++) use milliseconds since epoch , generate timestamp in given timezone (e.g. "europe/zurich"). can use local_date_time option :

posix_time ptime = epoch(date(1970,1,1)) + ms; //ms sent client tz_database tz; tz.load_from_file(/*path date_time_zonespec.csv*/); time_zone_ptr ptr = tz.time_zone_from_region(regionstr); //regionstr = europe/zurich local_date_time mytime(ptime, ptr); 

however, learnt post ( c++: choose boost::date_time or icu::date/time library?) boost::date_time time zone support broken. better option boost::locale. there way same steps above using boost::locale? searching examples online boost::locale not find example similar want.

perhaps free, open-source c++11/14 timezone library help:

#include "tz.h" #include <iostream>  date::zoned_time<std::chrono::milliseconds> convert(date::sys_time<std::chrono::milliseconds> tp) {     return date::make_zoned(date::locate_zone("europe/zurich"), tp); }  int main() {     using namespace std::chrono;     std::cout << convert(date::floor<milliseconds>(system_clock::now())) << '\n';     std::cout << convert(date::sys_time<milliseconds>{1469137715906ms}) << '\n'; } 

this output me:

2016-07-21 23:48:35.906 cest 2016-07-21 23:48:35.906 cest 

it built on top of c++11/14 <chrono> library. std::chrono::system_clock measures time since 1970-01-01 utc. timezone library helps translate localized timezones using iana timezone database.

fully documented, easy use. high performance. catches many errors @ compile time.

examples , recipes.


Comments