Project

General

Profile

Support #7587

Local to UTC time

Added by Bradley Looy about 1 year ago. Updated about 2 months ago.

Status:
Closed
Priority:
Low
Target version:
-
Start date:
05/28/2020
Due date:
% Done:

0%

Estimated time:

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?

#1

Updated by Bradley Looy about 1 year 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();

#2

Updated by Roel Standaert about 1 year 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

#3

Updated by Roel Standaert about 2 months ago

  • Description updated (diff)
  • Status changed from New to Closed

Also available in: Atom PDF