Home >Backend Development >PHP Problem >What should I do if the time obtained by php is inaccurate?

What should I do if the time obtained by php is inaccurate?

藏色散人
藏色散人Original
2021-02-23 09:43:422436browse

Solution to the inaccurate time obtained by php: 1. Open the php.ini file, and then modify the content to "date.timezone="PRC""; 2. Use the "date_default_timezone_set(")" method.

What should I do if the time obtained by php is inaccurate?

The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

Solution to the incorrect system time obtained by PHP

Using PHP to obtain the system time, I found that the time is wrong because the default time zone of PHP is UTC, and its time zone should be set to Beijing time.

Method 1: Modify php.ini File

Open the php.ini file: left-click the WampServer icon in the lower right corner - PHP - php.ini,

Look for date.timezone and find date.timezone = "UTC" ,

Change it to date.timezone = "PRC". If there is a semicolon on the left side of date.timezone, remove the semicolon.

<span class="cur_time"><?php echo "当前时间:" . date("Y-m-d H:i:s") ?></span>

Method 2: Use date_default_timezone_set(") Method;

<?php
date_default_timezone_set(&#39;PRC&#39;);
echo date("Y-m-d H:i:s");
?>

Recommended: "PHP Video Tutorial"

The second method I used, the test was successful

The above is the detailed content of What should I do if the time obtained by php is inaccurate?. For more information, please follow other related articles on the PHP Chinese website!

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