How can i get the timezone name from timestamp using moment.js?

Viewed 42

I have this timestamp string July 29, 2022 02:23 AM EDT and I want to extract the EDT timezone name from it using moment.js. Is there any method provided by momentjs. I didn't find any option.

Can you help?

2 Answers

Maybe this way will work for you.

var dateString = 'July 29, 2022 02:23 AM EDT';
var dateObj = new Date(dateString);
var momentObj = moment(dateObj);
var momentString = momentObj.format('YYYY-MM-DD');

You can split it

const date = "July 29, 2022 02:23 AM EDT";
const dateSplited = date.split(' ');
console.log(dateSplited[dateSplited.length-1]);

or you can use getTimezoneOffset() from Date, it's almost the same.

or for momentjs zone.abbr(timestamp);, documentation here

Related