Home >Backend Development >PHP Problem >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".
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 ).
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
#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('PRC'); //设置中国时区 ?>
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.
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!