Reputation: 259
I need a timestamp code similar to this JavaScript code:
new Date().getTime()
I tried this PHP code:
$date = new DateTime();
$ts = $date->getTimestamp();
which returns 1376399143
but the JavaScript code returns 1376399143263
, I think my PHP code generates a timestamp for only the date. How can I get the timestamp for the time portion as well?
Upvotes: 0
Views: 77
Reputation: 1642
The php code generates the timestamp for date and time, but it returns the number of seconds from 1-1-1970. Javascript returns the value in miliseconds.
You could use microtime(true)*1000;
for a similar result that Javascript.
Upvotes: 0
Reputation: 2540
use the code below
$time = mktime(date("H"),date("i"),date("s"),date("n"),date("j"),date("Y"));
echo $time;
for details information on mktime , check this link
Upvotes: 1
Reputation: 10717
You should use microtime
$seconds = microtime(true); // false = int, true = float
echo round(($seconds * 1000));
Upvotes: 0