Home >Backend Development >PHP Problem >How to change time zone in php

How to change time zone in php

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-09-29 16:14:142288browse

How to change time zone in php

Modify php.ini, find data.timezone = in php.ini and remove the ; sign in front of it, and then set data.timezone = "Asia/Shanghai".

How to change time zone in php

Use the function ini_set('date.timezone','Asia/Shanghai'); or date_default_timezone_set('Asia/Shanghai') in the program code of PHP 5 or above ).

How to change time zone in php

Related recommendations: "php Getting Started Tutorial"

Here are some commonly used time zone identifiers: Asia/Shanghai – Shanghai Asia /Chongqing – Chongqing Asia/Urumqi – Urumqi Asia/Hong_Kong – Hong Kong Asia/Macao – Macau Asia/Taipei – Taipei Asia/Singapore – Singapore

How to change time zone in php

#Function setting time zone method:

The code is as follows:

<?php function_exists(date_default_timezone_set);//在这他总是返回1,这函数是判断这里面的字符是不是一个定义了的函数名
date_default_timezone_set("Etc/GMT");//这是格林威治标准时间,得到的时间和默认时区是一样的
date_default_timezone_set("Etc/GMT+8");//这里比林威治标准时间慢8小时
date_default_timezone_set("Etc/GMT-8");//这里比林威治标准时间快8小时 
date_default_timezone_set(&#39;PRC&#39;); //设置中国时区
?>

How to change time zone in php

Function ini_set() sets the time zone: You can add ini_set('date.timezone','Asia/Shanghai') at the beginning of the file ; // 'Asia/Shanghai' is Shanghai time zone.

How to change time zone in php

The above is the detailed content of How to change time zone in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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