I have a time stamp I created with PHP that I would like to convert to the same format as new Date() in javaScript.
Here’s my code:
$current_timestamp = time();
//This returns a value such as 1268214657
I need to create a string using that timestamp that looks like this: Fri Mar 12 2010 01:50:33 GMT-0800 (Pacific Standard Time).
How can I create a string in php that has the same format as a new date would look like using new Date() in javaScript?
The
Dateclass has a constructor to pass in the number of milliseconds so multiply the PHP time in seconds by 1000:Output:
One issue you will face is the server generates time in one time zone, the client is in another. If you want to generate the timestamps on the server use the
date()function: