Home  >  Article  >  Backend Development  >  Problem of getting the current time difference of 8 hours in PHP_PHP tutorial

Problem of getting the current time difference of 8 hours in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:44:19731browse

echo date("Y-m-d H:i:s"); //Current time
?>

The time obtained by this method is 8 hours different from the standard time;

Starting from php5.1.0, the date.timezone option has been added to php.ini, which is turned off by default

That is, the time displayed (no matter what php command is used) is Greenwich Mean Time

It is exactly 8 hours different from our time (Beijing time). There are 3 methods below to restore the normal time.

1. The simplest way is not to use php5.1 or above

2. If you must use it and cannot modify php.ini, you need to add date_default_timezone_set (XXX) to the
statement about time initialization;
cp does not have this problem

3. Once and for all, only php.ini can be modified. Open php.ini and search for date.timezone. Remove the semicolon
= and add XXX after it. Restart the http service (such as apache2 or iis, etc.)

Regarding XXX, the available values ​​in mainland China are: Asia/Shanghai

Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in order, Macau, Hong Kong, Taipei)
And Singapore: Asia/Singapore

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478759.htmlTechArticle?php echo date("Y-m-d H:i:s"); //Current time? Obtained by this method The difference between the time and the standard time is 8 hours; starting from php5.1.0, the date.timezone option has been added to php.ini. By default...
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