Home > Backend Development > PHP Tutorial > 如何使用php输出时间格式_PHP

如何使用php输出时间格式_PHP

WBOY
Release: 2016-06-01 12:03:43
Original
985 people have browsed it
复制代码 代码如下:

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");
Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template