I have some code that tries to parse a date string.
When I do alert(Date("2010-08-17 12:09:36"));
It properly parses the date and everything works fine but I can’t call the methods associated with Date, like getMonth().
When I try:
var temp = new Date("2010-08-17 12:09:36");
alert(temp);
I get an “invalid date” error.
Any ideas on how to parse “2010-08-17 12:09:36” with new Date()?
Date()
With this you call a function called
Date(). It doesn’t accept any arguments and returns a string representing the current date and time.new Date()
With this you’re creating a new instance of Date.
You can use only the following constructors:
So, use
2010-08-17 12:09:36as parameter to constructor is not allowed.See w3schools.
EDIT:
new Date(dateString)uses one of these formats: