marnusw / date-fns-tz

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

date-fns-tz/format doesn't return timezone in IE #160

Open martin-badin opened 2 years ago

martin-badin commented 2 years ago

Hi guys.

format method doesn't return timezone in IE. Here is an example of my code. Could someone help me if the issue is in this library or not?

import { format } from "date-fns-tz";

console.log(format(new Date(), "z"));

The method returns '

marnusw commented 2 years ago

You need to use a polyfill to make it work on IE. Please confirm you are using one. See the docs.

martin-badin commented 2 years ago

I am using one from docs but it doesn't work.

navneetagrwl commented 2 years ago

Same Issue even with polyfill

Installed "date-time-format-timezone": "^1.0.22",

and added this in polyfills.ts file import 'date-time-format-timezone';

navneetagrwl commented 2 years ago

@marnusw

If I am passing 'America/Chicago' as time zone name I am getting CDT in IE format(new Date(), 'z', { timeZone: 'America/Chicago' }) but for Asia/Calcutta time zone name The method returns '

Any Idea why?

ayuthmang commented 6 months ago

@navneetagrwl I have the same issue with format that passed { timeZone: 'xxxxx' } as an option doesn't format correctly in a given timezone.

Instead, just use formatInTimeZone.

IMHO, if the format function doesn't use the timeZone option. Why don't we just remove it to not make ppl who use the lib confusing instead.