DateTimeZone 类
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
简介
时区表示。
类摘要
    
     class DateTimeZone
     {
    /* 常量 */
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /* 方法 */
    
    
public getTransitions(int 
   }$timestampBegin = PHP_INT_MIN, int $timestampEnd = PHP_INT_MAX): array|false预定义常量
- 
      DateTimeZone::AFRICAint
- 
      非洲时区。 
- 
      DateTimeZone::AMERICAint
- 
      美洲时区。 
- 
      DateTimeZone::ANTARCTICAint
- 
      南极洲时区。 
- 
      DateTimeZone::ARCTICint
- 
      北极时区。 
- 
      DateTimeZone::ASIAint
- 
      亚洲时区。 
- 
      DateTimeZone::ATLANTICint
- 
      大西洋时区。 
- 
      DateTimeZone::AUSTRALIAint
- 
      澳洲时区。 
- 
      DateTimeZone::EUROPEint
- 
      欧洲时区。 
- 
      DateTimeZone::INDIANint
- 
      印度洋(Indian)时区。 
- 
      DateTimeZone::PACIFICint
- 
      太平洋时区。 
- 
      DateTimeZone::UTCint
- 
      UTC 时区。 
- 
      DateTimeZone::ALLint
- 
      所有时区。 
- 
      DateTimeZone::ALL_WITH_BCint
- 
      所有时区,包含向后兼容。 
- 
      DateTimeZone::PER_COUNTRYint
- 
      每个国家的时区。 
更新日志
| 版本 | 说明 | 
|---|---|
| 8.4.0 | 类常量现已类型化。 | 
目录
- DateTimeZone::__construct — 创建新的DateTimeZone对象
- DateTimeZone::getLocation — 返回与时区相关的定位信息
- DateTimeZone::getName — 返回时区名称
- DateTimeZone::getOffset — 返回相对于 GMT 的时差
- DateTimeZone::getTransitions — Returns all transitions for the timezone
- DateTimeZone::listAbbreviations — 返回一个包含 dst (夏令时),时差和时区信息的关联数组。
- DateTimeZone::listIdentifiers — 返回包含了所有时区标识符的数字索引数组
  +添加备注
  
用户贡献的备注 1 note
  
  
  Jarmo Troska ¶
  
 
1 year ago
  Example of converting between timezones using the DateTime and DateTimeZone classes.
Note that PHP will also take care of calculating relevant daylight savings!
<?php
$utc_timezone = new DateTimeZone("UTC");
$tallinn_timezone = new DateTimeZone("Europe/Tallinn");
// Create a new DateTime object in the UTC format
$datetime = new DateTime("2023-01-01 11:00:00", $utc_timezone);
// Convert the DateTime object to the timezone of Tallinn
$datetime->setTimezone($tallinn_timezone);
// Display the result in the YYYY-MM-DD HH:MM:SS format
echo $datetime->format('Y-m-d H:i:s');
// Returns: 2023-01-01 13:00:00
?>