开发者

What is the PHP equivalent of Javascript's Date.UTC command?

How can I say this Javascript in PHP:

var ts=Date.UTC(1985,1,开发者_运维知识库22);


PHP's online docs are very useful: http://www.php.net/manual/en/ref.datetime.php

mktime takes args hour,minute,second,month,day,year.

$ts = mktime(0, 0, 0, 1, 22, 1985);

Date.UTC returns milliseconds whereas mktime returns seconds, so if you still want milliseconds, multiply by 1000.


$date = new DateTime(NULL, new DateTimeZone('UTC'));
$date->setDate(1985, 1, 22);
$ts = $date->getTimestamp();

EDIT: Corrected time zone parameter.


$ts = gmmktime(0, 0, 0, 2, 22, 1985) * 1000
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜