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?
I guess, somewhere in your code, the
moment
's default timezone is set to GMT+0530. Something likemoment.tz.setDefault('Asia/Colombo')
could do this.You can define in what timezone you want to display your date. This should work for you :
Or if you want the value I suggested in the comments :
For more informations about moment.js timezones, you can check the moment.js timezone docs.
Hope this helps !