php time() uses the date function and the local computer and server time are different_PHP tutorial

WBOY
Release: 2016-07-13 10:49:30
Original
828 people have browsed it

I recently configured a server in a wamp environment, but I found that the time is different from the local time, and the time obtained by using time and then using date displays a time difference. Let's take a look at the causes and solutions.

php time() uses the date function and the local computer and server time are different_PHP tutorial

If the date time is inconsistent, you can use date_default_timezone_set to set the time zone:

$time = date(Y."Year".m."Month".d."Day".G."Hour".i."Min");
The code is as follows
 代码如下 复制代码
";   //对当前时间进行计算 echo date('Y-m-d H:i:s',time()-600); //减10小时 echo "
";   //时间戳转时间 echo date('Y-m-d H:i:s',1364277600);   //时间转时间戳(仅精确到秒) echo strtotime("2013-03-26 14:00"); echo "
";  

?>

Copy code
"; ​ //Calculate the current time echo date('Y-m-d H:i:s',time()-600); //Subtract 10 hours echo "
"; ​ //Timestamp to time echo date('Y-m-d H:i:s',1364277600); ​ //Convert time to timestamp (accurate to seconds only) echo strtotime("2013-03-26 14:00"); echo "
"; ​

?>


Another way is to modify the configuration file in php.ini

Method 1:

date_default_timezone_set('PRC');

No return value. It’s OK to use the date function directly below
Method 2: Modify ;date.timezone = in php.ini to date.timezone = "Asia/Shanghai" (or change to date.timezone = "PRC") and remove the preceding semicolon, and restart Apache.

**Be sure to add quotation marks http://www.bkjia.com/PHPjc/632715.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/632715.html
TechArticle
Recently configured a server in wamp environment, but found that the time is different from the local time, and use time The obtained time is then used to display the time difference with date. Let’s introduce it together...
source:php.cn
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