Reputation: 15965
I have a string Mar 7 2012
.
How do I convert this to a Date object, so I can use mydate.getDate()
, mydate.getMonth()
, mydate.getFullYear()
etc?
Upvotes: 1
Views: 1989
Reputation: 598
I'd use Date.parse
in conjunction with Date#setTime
. For example:
var d = new Date();
d.setTime(Date.parse("Mar 7 2012"));
You've pretty good reference docs in mozilla's dev. network: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date
Upvotes: 0
Reputation: 79031
Well, Its pretty simple
var d =new Date("March 7 2012");
document.write(d.getMonth()); //use it
Upvotes: 2