Home > Backend Development > PHP Problem > Why is it inaccurate to get the current time in php

Why is it inaccurate to get the current time in php

藏色散人
Release: 2023-03-14 22:44:02
Original
2527 people have browsed it

php Solution to obtain inaccurate current time: 1. Open the php.ini file and modify the content to "date.timezone = "PRC""; 2. Use the "date_default_timezone_set('PRC');" code .

Why is it inaccurate to get the current time in php

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

Why is the current time obtained by php inaccurate?

PHP date() obtains the system time incorrectly

Using PHP to obtain the system time, I 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 .

Method 1: Modify the php.ini file

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

Search 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>
Copy after login

Method 2: Use the date_default_timezone_set(”) method;

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

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Why is it inaccurate to get the current time in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template