Support #7587
closedLocal to UTC time
0%
Description
If the user enters a date & time, say 5/28/2020 15:30. What is the best method for converting that local datetime to UTC?
Updated by Bradley Looy over 4 years ago
Would this be the preferred method?
WLocalDateTime local_datetime;
local_datetime.setDateTime(WDate(2020, 05, 28), WTime(15, 30, 0));
WDateTime utc_datetime = local_datetime.toUTC();
Updated by Roel Standaert over 4 years ago
That should work if the current locale is set to the right timezone. You can set it like this:
locale.setTimeZone(date::locate_zone(timeZoneName));
On Linux that should just work, because it comes with its own copy of the IANA time zone database. On Windows, there is a time zone database, but it is not compatible with our implementation. You'll have to download the time zone database instead: https://www.iana.org/time-zones. There are some more details in the locale
feature example: https://github.com/emweb/wt/tree/master/examples/feature/locale
Updated by Roel Standaert over 3 years ago
- Description updated (diff)
- Status changed from New to Closed