0

I'm sure this has been asked before, but I've definitely looked and cannot find an answer. I'd appreciate a link if this has an obvious/known solution.

I'm dealing with a legacy database where datetimes are stored as separate dates and times. The underlying datatypes in Postgres are "date" and "time without time zone [21:45:00]". Dates are in YYYY-MM-DD format, while times are HH:MM:SS. All records are from the same location, so the only difference comes from daylight savings.

Given a date string (YYYY-MM-DD), time (HH:MM:SS), and a known location (eg. "Europe/Oslo"), how can I construct a valid Javascript Date object with the appropriate timezone information?

Example inputs:

[
    { date: '2022-06-21', time: '21:45:00', location: 'Europe/Oslo' },
    { date: '2022-12-21', time: '21:45:00', location: 'Europe/Oslo' }
]

Desired output (valid UTC string or Date object equivalent):

['2021-06-21T19:45:00Z',
 '2021-12-21T20:45:00Z']
  • UTC is not a format, it's a time standard. The format in the OP is a commonly used ISO 8601 format with zero offset (which corresponds to UTC). This seems to be a duplicate of [*Calculate Timezone offset only for one particular timezone*](https://stackoverflow.com/questions/61361914/calculate-timezone-offset-only-for-one-particular-timezone), which is difficult to do without the support of a library. – RobG Nov 13 '22 at 11:11

0 Answers0