Home  >  Article  >  Backend Development  >  What should I do if the time obtained by php is wrong?

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

藏色散人
藏色散人Original
2020-07-22 09:26:283767browse

Solution to the incorrect time obtained by php: First open the "php.ini" file; then search for "date.timezone" and find "date.timezone="UTC""; finally change it to " date.timezone = "PRC"" is enough.

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

Solution to the incorrect system time obtained by PHP date()

Use PHP to obtain the system time and find that the time is incorrect , because the default time zone of PHP is UTC, and its time zone should be set to Beijing time.

Recommended: "PHP Tutorial"

Method 1: Modify the php.ini file

Open the php.ini file: Click the lower right corner with the left mouse button WampServer icon——PHP——php.ini,

Look for date.timezone, 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");
?>

The above is the detailed content of What should I do if the time obtained by php is wrong?. 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