MomentJS.format () produces the correct date -1 day in my timezone

I noticed that when I use momentJs to display a date in a specific format in my time zone, that day is lost.

I am in UTC-4: 30 time zone.

This does not occur in all time zones; noted that this works correctly in the UTC-5: 00 time zone.

The following are the results of console.log:


The correct conclusion:

moment([2013, 0, 24]) 

Moment
_a: Array [8]
_d: Thu January 24, 2013 00:00:00 GMT-0430 (standard time in Venezuela)
_isUTC: false
_lang: false
_proto: Object

 moment([2013, 0, 24]).toDate() 

Thu Jan 24 2013 00:00:00 GMT-0430 (standard time in Venezuela)


Invalid output:

 moment('01/24/2013').format('MM/DD/YYYY') 

"01/23/2013"

 moment([2013, 0, 24]).format('MM/DD/YYYY') 

"01/23/2013"


Note that as soon as the .format () method is used, the day is lost, and the 23rd is instead of the 24th.


Can anyone explain this behavior? Again, this seems time zone specific.

+6
source share
1 answer

I set my time zone to (UTC-4:30) Caracas , and then checked the value:

 moment('01/24/2013').format('MM/DD/YYYY') 

It returned correctly on 01/24/2013 , so I cannot reproduce the problem you described.

I am checking with moment.js 2.0.0. on Google Chrome 27.0.1453.116m running on Windows 8.

Perhaps this is due to an older version of moment.js. Could you confirm?

0
source

All Articles