user3152849 user3152849 - 6 months ago 20
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.

Answer

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'));