[英]PHP return JS UTC date format
Is there any way I can return a date using PHP that is the same format that Date.UTC(y,m,d) returns? 有没有办法可以使用与Date.UTC(y,m,d)返回的格式相同的PHP返回日期?
Here is an example of the format I need: 以下是我需要的格式示例:
1274745600000 (Apr 25, 2010) 1274745600000(2010年4月25日)
PHP: PHP:
$date = '13-09-2010 00:00:00';
date_default_timezone_set('UTC');
echo (strtotime($date) * 1000) - (strtotime('02-01-1970 00:00:00') * 1000);
//1286928000000
Javascript: 使用Javascript:
Date.UTC(2010, 9, 13);
//1286928000000
[EDITed]: [编辑]:
The way it returns OUTPUT is the milliseconds from January 1, 1970 to July 8, 2005, according to universal time: which you can get by mktime
and appending three 0
like this: 它返回OUTPUT的方式是从1970年1月1日到2005年7月8日的毫秒,根据通用时间:你可以通过
mktime
得到它并像这样追加三个0
:
echo mktime(0, 0, 0, 9, 15, 2010).'000';
This will display: 这将显示:
1284508800000
1284508800000
And you can use date function to get in JS UTC INPUT format: 您可以使用日期函数来获取JS UTC INPUT格式:
echo date("Y,n,j");
This will display: 这将显示:
2010,9,15
2010,9,15
Inside your function use 在你的功能里面使用
date_default_timezone_set('UTC');
This set the default timezone to use. 这设置了要使用的默认时区。 Available since PHP 5.1.And you can simply echo date by date() function.
自PHP 5.1起可用。您可以简单地按日期()函数回显日期 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.