In PHP if i have:
$date = "2012-01-18 16:00";
I can do:
$newDate = new DateTime($date);
In JS (jQuery) i have:
var date = "2012-01-18 16:00";
why i can’t:
var newDate = new Date(date);
? This return me Invalid date.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In order for that string to be parsed, you need a T between the date and the time
so to fix your original code:
DEMO
The Date constructor will also take a year, month, and day
though to get that to work you’d have to split your string up.