user3152849 user3152849 - 1 year ago 81
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 Source

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'));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download