moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.23k stars 730 forks source link

Timezones aren't working properly #1468

Closed marcus-sa closed 1 year ago

marcus-sa commented 1 year ago
import { DateTime } from 'luxon';

const now = DateTime.now();

console.log(
  now.setZone('UTC').toJSDate(),
  now.setZone('Europe/Copenhagen').toJSDate(),
  now.setZone('America/New_York').toJSDate(),
);

Results in the following being logged

2023-07-17T11:02:34.419Z 2023-07-17T11:02:34.419Z 2023-07-17T11:02:34.419Z

The dates are exactly the same?

I expected the following to be logged

2023-07-17T11:02:34.419Z 2023-07-17T13:02:34.419Z 2023-07-17T15:02:34.419Z
marcus-sa commented 1 year ago

Had to use setZone(..., { keepLocalTime: true })