Format datetime to YYYY-MM-DD HH:mm:ss in moment.js

I have a string in this format:

var dateTime = "06-17-2015 14:24:36"

I am using moment.js and I am trying to convert it into YYYY-MM-DD HH:mm:ss -> 2015-06-17 14:24:36.

I have tried this method

dateTime = moment( dateTime, 'MM-DD-YYYY HH:mm:ss',true).format("YYYY-MM-DD HH:mm:ss");

But getting dateTime as Invalid Date.

Answers


Try this. You should be able to get the date in the correct format.

var dateTime = new Date("2015-06-17 14:24:36");
dateTime = moment(dateTime).format("YYYY-MM-DD HH:mm:ss");

Need Your Help

Purpose of "return" statement in Scala?

java scala return

Is there any real reason of providing the return statement in Scala? (aside from being more "Java-friendly")

Easiest way to toggle 2 classes in jQuery

jquery toggleclass

If I have class .A and class .B and want to switch in between on button click, what's a nice solution for that in jQuery? I still don't understand how toggleClass() works.