Question

Issues is parsing date using Moment js library

I'm using Moment js library to format date from Json. Date format in json is 2012-09-28 16:18:02 -0400. I want to convert it into this format on client side in this format : 19th Aug 2012 at 10:50 pm. This is what i tried out...

var a= moment("2012-09-28 16:18:02 -0400");
var day=a.format("Do MMMM YYYY, h:mm:ss a");
console.log(day);   //Outputs  28th September 2012, 9:30:00 am

But everytime it shows 9:30:00 am.

How can i resolve this ?

Était-ce utile?

La solution

Try adding date format as second parameter to moment(...):

var a= moment("2012-09-28 16:18:02 -0400", "YYYY-MM-DD hh:mm:ss Z");
var day=a.format("MMMM Do YYYY, h:mm:ss a");
console.log(day); ​
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top