admin管理员组文章数量:1359237
Is there any way I can return a date using PHP that is the same format that Date.UTC(y,m,d) returns?
Here is an example of the format I need:
1274745600000 (Apr 25, 2010)
Is there any way I can return a date using PHP that is the same format that Date.UTC(y,m,d) returns?
Here is an example of the format I need:
1274745600000 (Apr 25, 2010)
Share Improve this question edited Sep 15, 2010 at 4:04 Ian McIntyre Silber asked Sep 15, 2010 at 3:25 Ian McIntyre SilberIan McIntyre Silber 5,66313 gold badges56 silver badges76 bronze badges3 Answers
Reset to default 6PHP:
$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:
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:
echo mktime(0, 0, 0, 9, 15, 2010).'000';
This will display:
1284508800000
And you can use date function to get in JS UTC INPUT format:
echo date("Y,n,j");
This will display:
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.
本文标签: javascriptPHP return JS UTC date formatStack Overflow
版权声明:本文标题:javascript - PHP return JS UTC date format - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744082126a2587837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论