Home > Backend Development > PHP Tutorial > The time zone output time of the date function in php is incorrect_PHP tutorial

The time zone output time of the date function in php is incorrect_PHP tutorial

WBOY
Release: 2016-07-13 10:56:32
Original
850 people have browsed it

In PHP, if we don’t make any settings, generally using date to output time will have errors, and it will be very large.

Question: echo date('o-m-j H:i');

[Date]
The code is as follows
 代码如下 复制代码

〈?php
         echo date(’Y-m-d H:i:s’);
  ?〉

Copy code



〈?php echo date(’Y-m-d H:i:s’);

?〉


Output the current time: 2008-10-12 02:32:17

Weird, the actual time is: 2008-10-12 10:32:17

The output result differs from local time by 8 hours.
Cause: The time zone is not set correctly.

Two solutions:

1. Add date_default_timezone_set('Asia/Shanghai');
 代码如下 复制代码
date_default_timezone_set(‘PRC’);
2. Modify php.ini
; Defines the default timezone used by the date functions

date.timezone = PRC Note: PRC is the People’s Republic of China

before calling the date() method http://www.bkjia.com/PHPjc/632149.htmlwww.bkjia.com
true
http: //www.bkjia.com/PHPjc/632149.html
TechArticleIn php, if we don’t make any settings, generally there will be errors in using date to output time, and it will be very large. . Question: echo date('o-m-j H:i'); The code is as follows Copy the code 〈?php e...
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