Friday, 25 December 2020

How to detect timezone abbreviation using date-fns-tz?

I want to print timeZone abbreviation like: IST, UTC, PST, MST, CST, EST, etc...

I'm migrating my code from momentJS to date-fns and having the following issue. When I was using momentJS everything was working as expected. For example, the code below will print "IST"

const timeZone = 'Asia/Calcutta';
moment.tz(new Date(), timeZone).format('z'); // IST

Demo using MomentJS

Now my code using date-fns works but not all the way because it prints "India Standard Time" and I only want to print IST.

format(parisDate, 'zzzz', { timeZone: 'Asia/Calcutta', locale: enGB }); // India Standard Time

Can anyone tell me what I'm missing or doing wrong? Here's a live demo of my code: date-fns DEMO



from How to detect timezone abbreviation using date-fns-tz?

No comments:

Post a Comment