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');
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 |
[Date]
; Defines the default timezone used by the date functions
date.timezone = PRC Note: PRC is the People’s Republic of China
If you do not have permission to modify php.ini, you should add before calling the date() method
http://www.bkjia.com/PHPjc/632149.htmlwww.bkjia.com
trueTechArticleIn 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...
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