Reputation: 11642
I have datetime as string, fxp:
2014-11-10 12:12
And I need create from this string Date object with correctly set months (in object months starting from 0).
So i tried this:
var d = Date.parse("2014-11-10 12:12");
But it seems to be not working.
console.log("Month is " + d.getMonth());
Is not giving result.
How can i parse and create date object from string correctly?
Thanks for any help.
Upvotes: 1
Views: 39
Reputation: 12213
Date.parse
method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
You cant parse the Month from that value. You have to use a new Date object.
Try:
var d = new Date("2014-11-10 12:12");
console.log("Month is " + d.getMonth());
Upvotes: 1