php时间问题

来源:百度知道 编辑:UC知道 时间:2024/05/06 00:22:15
<?php
echo date("Y-m-d H:i:s");
?>
输出为2007-10-17 05:39:44
而系统右下角的时间是13:40
差8个小时。
请问我怎样设置才可以
直接运行上面的代码出来的是我现在的本机时间。
不要用date("Y-m-d H:i:s",tims()+8*3600)

方法1 date_default_timezone_set() 函数
方法2 php.ini

[Date]
; Defines the default timezone used by the date functions
date.timezone =

PHP输出的是服务器时间~~

你的服务器可能时间有问题

如果需要本机时间..用JS

<script language="javascript">
var nowtime = new Date();
document.write(nowtime.getYear() + "年" + nowtime.getMonth() + "月" + nowtime.getDay() + "日");
</script>

可以在php.ini里设置

[Date]
; Defines the default timezone used by the date functions
date.timezone = Asia/shangHai