Skip to content
Advertisement

Convert PHP date into javascript date format

I have a PHP script that outputs an array of data. This is then transformed into JSON using the json_encode() function.

My issue is I have a date within my array and it’s not in the correct JavaScript format. How can I convert this within PHP so it is?

JavaScript

Instead of the above for the date I need the equivalent of the JavaScript function

new Date()

When I output the above I get the following “Fri Jun 01 2012 11:08:48 GMT+0100 (GMT Daylight Time)” However, If I format my PHP date to be the same, then JavaScript rejects it. Confused…

Can anyone help?

Advertisement

Answer

You should probably just use a timestamp

JavaScript

Then convert it to a Javascript date

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement