Solution to php getting time error: First find and open the "php.ini" file; then look for "date.timezone" and find "date.timezone="UTC""; finally change it to "date.timezone="PRC"" is enough.
Solution to the error in PHP getting the system time
Using PHP to get 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 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, change it Remove the semicolon.
<span class="cur_time"><?php echo "当前时间:" . date("Y-m-d H:i:s") ?></span>
Method 2: Use the date_default_timezone_set(”) method;
<?php date_default_timezone_set('PRC'); echo date("Y-m-d H:i:s"); ?>
The second method I used, Test successful
For more related knowledge, please visitPHP Chinese website!
The above is the detailed content of What to do if php gets the time wrong. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
