略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 美洲

2024-11-14

美洲

美洲
America/Adak America/Anchorage America/Anguilla America/Antigua
America/Araguaina America/Argentina/Buenos_Aires America/Argentina/Catamarca America/Argentina/Cordoba
America/Argentina/Jujuy America/Argentina/La_Rioja America/Argentina/Mendoza America/Argentina/Rio_Gallegos
America/Argentina/Salta America/Argentina/San_Juan America/Argentina/San_Luis America/Argentina/Tucuman
America/Argentina/Ushuaia America/Aruba America/Asuncion America/Atikokan
America/Bahia America/Bahia_Banderas America/Barbados America/Belem
America/Belize America/Blanc-Sablon America/Boa_Vista America/Bogota
America/Boise America/Cambridge_Bay America/Campo_Grande America/Cancun
America/Caracas America/Cayenne America/Cayman America/Chicago
America/Chihuahua America/Costa_Rica America/Creston America/Cuiaba
America/Curacao America/Danmarkshavn America/Dawson America/Dawson_Creek
America/Denver America/Detroit America/Dominica America/Edmonton
America/Eirunepe America/El_Salvador America/Fort_Nelson America/Fortaleza
America/Glace_Bay America/Goose_Bay America/Grand_Turk America/Grenada
America/Guadeloupe America/Guatemala America/Guayaquil America/Guyana
America/Halifax America/Havana America/Hermosillo America/Indiana/Indianapolis
America/Indiana/Knox America/Indiana/Marengo America/Indiana/Petersburg America/Indiana/Tell_City
America/Indiana/Vevay America/Indiana/Vincennes America/Indiana/Winamac America/Inuvik
America/Iqaluit America/Jamaica America/Juneau America/Kentucky/Louisville
America/Kentucky/Monticello America/Kralendijk America/La_Paz America/Lima
America/Los_Angeles America/Lower_Princes America/Maceio America/Managua
America/Manaus America/Marigot America/Martinique America/Matamoros
America/Mazatlan America/Menominee America/Merida America/Metlakatla
America/Mexico_City America/Miquelon America/Moncton America/Monterrey
America/Montevideo America/Montserrat America/Nassau America/New_York
America/Nipigon America/Nome America/Noronha America/North_Dakota/Beulah
America/North_Dakota/Center America/North_Dakota/New_Salem America/Nuuk America/Ojinaga
America/Panama America/Pangnirtung America/Paramaribo America/Phoenix
America/Port-au-Prince America/Port_of_Spain America/Porto_Velho America/Puerto_Rico
America/Punta_Arenas America/Rainy_River America/Rankin_Inlet America/Recife
America/Regina America/Resolute America/Rio_Branco America/Santarem
America/Santiago America/Santo_Domingo America/Sao_Paulo America/Scoresbysund
America/Sitka America/St_Barthelemy America/St_Johns America/St_Kitts
America/St_Lucia America/St_Thomas America/St_Vincent America/Swift_Current
America/Tegucigalpa America/Thule America/Thunder_Bay America/Tijuana
America/Toronto America/Tortola America/Vancouver America/Whitehorse
America/Winnipeg America/Yakutat America/Yellowknife  
add a noteadd a note

User Contributed Notes 14 notes

up
92
opensource at matheusd dot com
6 years ago
Helpful tip for Brazilian coders in need of timezone information. Here follows the list of timezones used by each state (source: https://en.wikipedia.org/wiki/Time_in_Brazil):

$timezones = array(
'AC' => 'America/Rio_branco',   'AL' => 'America/Maceio',
'AP' => 'America/Belem',        'AM' => 'America/Manaus',
'BA' => 'America/Bahia',        'CE' => 'America/Fortaleza',
'DF' => 'America/Sao_Paulo',    'ES' => 'America/Sao_Paulo',
'GO' => 'America/Sao_Paulo',    'MA' => 'America/Fortaleza',
'MT' => 'America/Cuiaba',       'MS' => 'America/Campo_Grande',
'MG' => 'America/Sao_Paulo',    'PR' => 'America/Sao_Paulo',
'PB' => 'America/Fortaleza',    'PA' => 'America/Belem',
'PE' => 'America/Recife',       'PI' => 'America/Fortaleza',
'RJ' => 'America/Sao_Paulo',    'RN' => 'America/Fortaleza',
'RS' => 'America/Sao_Paulo',    'RO' => 'America/Porto_Velho',
'RR' => 'America/Boa_Vista',    'SC' => 'America/Sao_Paulo',
'SE' => 'America/Maceio',       'SP' => 'America/Sao_Paulo',
'TO' => 'America/Araguaia',    
);
up
60
kapahala11 at yahoo dot com
15 years ago
Note that "America" means "the continents of North and South America, including the Caribbean islands".  It does *not* mean "The United States Of America".

If you're looking for the Hawaii timezone, you'll find it in Pacific/Honolulu (not America/Honolulu).
up
25
mad_elf at maranelda dot org
2 years ago
Since I just had to make up this list myself, here for posterity are the timezone mappings for Canada:

Newfoundland ...... America/St_Johns
Atlantic .......... America/Halifax
Atlantic no DST ... America/Blanc-Sablon
Eastern ........... America/Toronto
Eastern no DST .... America/Atikokan
Central ........... America/Winnipeg
Central no DST .... America/Regina
Mountain .......... America/Edmonton
Mountain no DST ... America/Creston
Pacific ........... America/Vancouver
up
64
eslindsey at gmail dot com
8 years ago
For the United States:

Eastern ........... America/New_York
Central ........... America/Chicago
Mountain .......... America/Denver
Mountain no DST ... America/Phoenix
Pacific ........... America/Los_Angeles
Alaska ............ America/Anchorage
Hawaii ............ America/Adak
Hawaii no DST ..... Pacific/Honolulu

Source: http://stackoverflow.com/questions/4989209/list-of-us-time-zones-for-php-to-use
up
2
Jalaluddin Qureshi
1 year ago
To display the current time for Toronto,

$dtz = new DateTimeZone("America/Toronto");
$dt = new DateTime("now", $dtz);

//Stores time as "2021-04-04T13:35:48":
$currentTime = $dt->format("Y-m-d") . "T" . $dt->format("H:i:s")

//Stores time as "2021-04-04T01:35:20":
$currentTime = $dt->format("Y-m-d") . "T" . $dt->format("h:i:s")
up
4
knowEnoughToGetMyselfInTrouble
5 years ago
I had an issue I feel pertinent to add to the conversation here in regard to running local testing servers with the likes of XAMPP.

Initially I noticed a variable I had $currentDay == date('l');
was returning the incorrect day as I tested my code which I hashed over thoroughly and found no visual errors. All the code seemed to be correct, except I was getting results from my query and var_dump($currentDay) using that variable that were for the following day as I typically work into the night. I then used "echo date_default_timezone_get();" to further test and compare the results.

I searched as "cjacunad at gmail dot com" had suggested in the php.ini file and low and behold, there was the issue. Running a localhost through PHPmyadmin(XAMPP) I found my date.timezone setting was indeed set to Germany/Berlin. I set it to the suggested setting for America/Los_Angeles first and had an error in phpinfo() file under the date.timezone setting. It had defaulted to UTC. 

So I searched around a bit and found a working solution for my localhost php.ini file:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "US/Pacific"

After saving and rebooting my localhost Apache server, the phpinfo(); file returned the proper setting for date.timezone. I then tested my code and found it to be working flawlessly.

I hope this helps anyone with similar issues I was facing with my localhost timezone setting.
up
1
Anonymous
2 years ago
For those reporting that timezone values above don't work, it may be due an older version of PHP.  

https://www.php.net/manual/en/timezones.others.php 
>Warning
>Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons, and may expose erroneous behavior.

For example the value "US/Pacific" is no longer supported, but may be necessary for backwards compatibility reasons.

Further details, and the deprecated values are listed at the link above. 

From the main timezones page (https://www.php.net/manual/en/timezones.php), you can arrive at the deprecated values page via the "Others" link.
up
0
Sajith Karunatilake
7 months ago
For [ date_default_timezone_set("America/New_York"); ]
Most Used Timezones:

For the United States:

Eastern --------------- America/New_York
Central --------------- America/Chicago
Mountain -------------- America/Denver
Mountain no DST ------- America/Phoenix
Pacific --------------- America/Los_Angeles
Alaska ---------------- America/Anchorage
Hawaii ---------------- America/Adak
Hawaii no DST --------- Pacific/Honolulu

For Canada:

Newfoundland ---------- America/St_Johns
Atlantic -------------- America/Halifax
Atlantic no DST ------- America/Blanc-Sablon
Eastern --------------- America/Toronto
Eastern no DST -------- America/Atikokan
Central --------------- America/Winnipeg
Central no DST -------- America/Regina
Mountain -------------- America/Edmonton
Mountain no DST ------- America/Creston
Pacific --------------- America/Vancouver
up
0
Zeusstl
2 years ago
To get the short timezone value like EDT, you can just use T in the date format. As in,
date->format("H:i:s T")

This would output something like:
13:22:14 EDT
up
3
cjacunad at gmail dot com
13 years ago
You can set a default time zone for your server from the configuration file (php.ini) at the line:

[Date]
; Defines the default timezone used by the date functions
date.timezone = America/New_York
up
0
Paul Smalley
2 years ago
Remember to use underscore "_" instead of any spaces when referencing time zones.
up
0
braulio dot apc at hotmail dot com
5 years ago
For Mexico (México):

Northwest --------- America/Tijuana

Pacific ----------- America/Mazatlan or America/Chihuahua

Central ----------- America/Mexico_City or America/Matamoros or America/Monterrey or America/Merida

South east -------- America/Cancun

Source: http://www.cenam.mx/hora_oficial/
up
-4
Anonymous
3 years ago
I had been receiving the warning

PHP Warning:  Unknown: Invalid date.timezone value '“America/Moncton”'.

When I set this, I had copied the 'America/Moncton' setting from a website, but copied the quotation marks, which were incorrect - the web site had < “ and ” >, instead of the proper < " >

Changing out my quotation marks fixed the issue
up
-23
Sheryl
4 years ago
"KnowEnough..." reported that "America/Los Angeles" didn't work as a time zone in php.ini or as a parameter to date_default_timezone_set(). I, too, found that the time zone listed in the PHP documentation didn't work. I'm somewhere else in America, so I made a guess and used "US/Eastern" rather than "America/New York", as listed in the docs. It worked! If you use it in php.ini, you need to restart Apache.

It seems like the real parameter for the US is "US/timezone-name".

官方地址:https://www.php.net/manual/en/timezones.america.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3