marnusw / date-fns-tz

Complementary library for date-fns v2 adding IANA time zone support
MIT License
1.07k stars 116 forks source link

Timezones always getting returned in my local time #295

Open ttante opened 2 months ago

ttante commented 2 months ago

I've been using this module for months and recently updated to v3. Since then I can't seem to get a timestamp to show up in any other timezone.

If i provide a timestamp with the format of '2024-08-20T19:07:45.603000' and try to convert it it EST (using 'America/New_York') I get something like this: "Tue Aug 20 2024 19:07:45 GMT-0500 (Central Daylight Time)}".

I have tried toZonedTime, fromZonedTime, and format and all solo and in combination with an initial conversion to UTC & gathering the offset and subtracting the offset in milliseconds. No matter what I end up with my local time at the end.

Running new Date('2024-08-20T19:07:45.603000') coerces the timezone into my local time on a browser, but not in node. I don't know if this is a new update to the Date initializer, but the result is that I can't get my times to be recognized in the correct timezone (they actually are in 'America/New_York' time).

I suspect this issue may be due to the use of new Date() in the date-fns-tz library. At this point I've had to look into Luxon and other libraries for this, but I was really enjoying the module and I'm really confused as to why this is happening.

yepMad commented 1 month ago

Same

MarcosEscobarR commented 1 month ago

same

kossnocorp commented 1 month ago

Node.js and browser parse date strings consistently (albeit confusing).

Node.js:

image

Browser:

image

You might want to use parseISO for such strings:

image

ggPeti commented 4 weeks ago
image

might be related