Home > Backend Development > PHP Tutorial > What should I do if the time output by the date() function in PHP is inconsistent with Linux?

What should I do if the time output by the date() function in PHP is inconsistent with Linux?

青灯夜游
Release: 2023-04-08 14:36:02
forward
3072 people have browsed it

What should I do if the time output by the date() function in PHP is inconsistent with the Linux time? How to deal with it? The following article will introduce you to the solution. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What should I do if the time output by the date() function in PHP is inconsistent with Linux?

Cause: Use PHP to get the time and find that the time is wrong. This is because the default time zone of PHP is UTC, Universal Time Coordinated (UTC). The solution is to set the time to Beijing time.

1. Modify the php.ini file

1. Open the php.ini file

2. Search for date.timezone and find; date.timezone =

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

4. Restart php

service php-fpm restart
Copy after login

2. Use date_default_timezone_set('') method

Add the following code at the beginning of the php program

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

For more related knowledge, please pay attention to PHP中文网! !

The above is the detailed content of What should I do if the time output by the date() function in PHP is inconsistent with Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template