Home  >  Article  >  Backend Development  >  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?

青灯夜游
青灯夜游forward
2020-04-18 09:12:113019browse

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

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");
?>

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete