HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.14k stars 677 forks source link

After change zone, how to convert zoned_time to time_point #720

Closed xjsxujingsong closed 2 years ago

xjsxujingsong commented 2 years ago

As described. time_point t = system_clock::now(); auto zone = date::locate_zone("Australia/Sydney"); zoned_time tt = make_zoned(zone, t); How to convert tt back to time_point?

HowardHinnant commented 2 years ago

Doing some drive-by simplifications:

auto t = system_clock::now();
auto zone = date::locate_zone("Australia/Sydney");
zoned_time tt{zone, t};
t = tt.get_sys_time();  // UTC time_point
auto lt = tt.get_local_time();  // local time_point
xjsxujingsong commented 2 years ago

Hi @HowardHinnant Thanks for your prompt response. I would like to convert zoned_time to chrono::time_point (back to standard C++ format)

xjsxujingsong commented 2 years ago

Just found it. Thanks. auto cc = clock_cast(t); auto dd = clock_cast(lt);

HowardHinnant commented 2 years ago

Just tt.get_sys_time(); is all you need.