Home  >  Article  >  Backend Development  >  How to change time zone to US East in php

How to change time zone to US East in php

青灯夜游
青灯夜游Original
2022-02-11 17:50:512244browse

Modification method: 1. Use the "ini_set('date.timezone', 'America/New_York');" statement; 2. Use the "date_default_timezone_set('America/New_York');" statement.

How to change time zone to US East in php

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:


'; ini_set('date.timezone', 'America/New_York'); echo '美国/东部的当前时间为:' . date('Y-m-d H:i:s', time()) ; ?>

How to change time zone to US East in php

Set the value of the

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:


How to change time zone to US East in php

Recommended learning: "

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!

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