Moment JS setting TimeZone to EST - alloy/moment

5.9k views Asked by At

I am using momentjs in alloy framework in Appcelerator. My api returns the date as - 2017-09-06T12:03:00.000Z I am using below code to format this date into readable form -

var dt =  moment(record.createddate);
$.dateValue.text = moment(dt).format('lll');

But the output I get is - Sep 6, 2017 5:33 PM, which is not correct as the date saved in db and returned from api is EST and the date getting displayed is GMT+0530. How should i format this date so that I get the correct date value?

1

There are 1 answers

1
Ilshidur On

I guess, somewhere in your code, the moment's default timezone is set to GMT+0530. Something like moment.tz.setDefault('Asia/Colombo') could do this.

You can define in what timezone you want to display your date. This should work for you :

moment('2017-09-06T12:03:00.000Z').tz("Etc/GMT").format('lll')

Or if you want the value I suggested in the comments :

moment('2017-09-06T12:03:00.000Z').tz("Etc/GMT-2").format('lll')

For more informations about moment.js timezones, you can check the moment.js timezone docs.

Hope this helps !