Home  >  Article  >  Backend Development  >  How to set time zone in php

How to set time zone in php

王林
王林Original
2020-07-31 14:42:593179browse

How to set the time zone in php: You can use the function ini_set('date.timezone','Asia/Shanghai') to set the time zone. You can also use the function date_default_timezone_set('Asia/Shanghai') to set it.

How to set time zone in php

Use the function date_default_timezone_set('Asia/Shanghai'); in the program code of PHP 5 or above to set the time zone, you can also add # at the beginning of the file ##

ini_set('date.timezone','Asia/Shanghai'); // 'Asia/Shanghai' 为上海时区

(Recommended tutorial:

php graphic tutorial)

Code example:


<?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;); //设置中国时区
?>

You can also modify the php.ini configuration file. Set time zone.

(Video tutorial recommendation:

php video tutorial)

Find the configuration "data.timezone" in php.ini, remove the ; sign in front of it, and then set it manually data.timezone = “Asia/Shanghai”; That’s it.

Description of 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

The above is the detailed content of How to set 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