user3152849 user3152849 - 10 months ago 44
AngularJS Question

I am getting wrong date after converting by moment.js

My code is
console.log(moment(new Date('2016-05-24T18:50:05.000')).format('LL'));

it should be 24 may 2016 but it gives me 25 may 2016. can any one help me.


You need to specify the date as UTC, you can do so in either of the following ways:

console.log(moment(new Date('2016-05-24T18:50:05.000Z')).format('LL'));

Where, the Z specifies that the time is UTC. Or:

console.log(moment.utc(new Date('2016-05-24T18:50:05.000')).format('LL'));