date_default_timezone_set("ETC/GMT-8");
$tm=time();
echo date("Y-m-d h:i a",$tm);
echo "
";
echo date("Y年m月d日",$tm);
?>
PHP默认的时区UTC时区,而北京正好位于该时区的东八区,领先UTC时区8个小时,所以在PHP中使用time()函数获取的当前时间总是相差8个小时。
可以通过以下两种方式配置:
1.修改php.ini文件中的date.timezone的值
2.使用专门设置时区的函数,date_default_timezone_set("ETC/GMT-8");
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn