获取日期+时间戳

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?

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

You could use microtime, but if you do not need the additional precision (which will get lost because of networking), just divide the javascript time by 1000.

You should use microtime

$seconds = microtime(true); // false = int, true = float 
echo round(($seconds * 1000));

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.