How can I pass a datetime/timestamp from PHP to javascript. The following does not appear to work:
startLive = new Date(<?php echo date("U", strtotime($start_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.
Try this:
Explanation:
PHP’s
strtotimefunction returns a Unix timestamp (seconds since 1-1-1970 at midnight).Javascript’s
Date()function can be instantiated by specifying milliseconds since 1-1-1970 at midnight.So multiply seconds by 1000 and you get milliseconds, which you can use in Javascript.