Home >Backend Development >PHP Problem >How to change time zone to US East in php
Modification method: 1. Use the "ini_set('date.timezone', 'America/New_York');" statement; 2. Use the "date_default_timezone_set('America/New_York');" statement.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Division of time zones
The world is divided into 24 time zones. Each time zone has its own local time. The local time in each time zone differs from 1 to 23 hours at the same time. For example, the local time in London, UK and the local time in Beijing The time difference is 8 hours.
In the field of international radio communications, a unified time is used, called Universal Time Coordinated (UTC). UTC is the same as Greenwich Mean Time (GMT).
phpChange the time zone to East America
1. Use the ini_set() function to set
## The #ini_set() function can set the value of a specified configuration option. This configuration option will maintain the new value while the script is running, and will be restored when the script ends. The syntax format of the function is as follows:ini_set($varname, $newvalue)where $varname is the configuration option to be modified, and $newvalue is the new value of the configuration option. Example:
<?php header("Content-type:text/html;charset=utf-8"); ini_set('date.timezone', 'Asia/Shanghai'); echo '上海的当前时间为:' . date('Y-m-d H:i:s', time()). '<br><br>'; ini_set('date.timezone', 'America/New_York'); echo '美国/东部的当前时间为:' . date('Y-m-d H:i:s', time()) ; ?>
date.timezonex item to "America/New_York", that is, " United States/New York" will do.
New York is in the eastern part of the United States. New York is located in the northeastern part of the East Coast of the United States, at the mouth of the Hudson River in the southeastern part of New York State, about halfway between Washington, D.C., and Boston, and close to the Hudson River.
2. Use date_default_timezone_set() function
date_default_timezone_set() function can set a default time zone for all time and date functions in the script. Its syntax format is as follows :date_default_timezone_set($timezone_identifier)The parameter $timezone_identifier is the time zone identifier, such as UTC (Greenwich Mean Time) or Europe/Lisbon (Portugal). Example:
<?php header("Content-type:text/html;charset=utf-8"); date_default_timezone_set('America/New_York'); echo '美国/东部的当前时间为:' . date('Y-m-d H:i:s', time()) ; ?>
PHP Video Tutorial"
The above is the detailed content of How to change time zone to US East in php. For more information, please follow other related articles on the PHP Chinese website!