Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moment.tz() fails when I use it in ES6/react?

Why does moment-timezone fail when I use it in ES6 javascript file?

import moment from 'moment';
// import timezone from 'moment-timezone';

const formatTime = ({timestamp}) => {
    const formattedDT = moment.tz(timestamp, 'America/Los_Angeles').format('YYYY-MM-DD HH:mm ZZ');
    return formattedDT;
};
like image 538
Neha M Avatar asked Jul 18 '18 22:07

Neha M


1 Answers

UPD for 2018 (ES6/React), this works when using npm version of moment-tz

import moment from 'moment-timezone';

moment.tz(moment.tz.guess()).zoneAbbr();
like image 147
Artem Bernatskyi Avatar answered Sep 30 '22 05:09

Artem Bernatskyi