亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

PHP 菜鳥(niǎo)教程

PHP 高級(jí)教程

PHP & MySQL

PHP 參考手冊(cè)

PHP timezone_open() 函數(shù)用法及示例

PHP Date & Time 函數(shù)手冊(cè)

timezone_open()函數(shù)創(chuàng)建新的DateTimeZone對(duì)象

定義和用法

timezone_open()函數(shù)是DateTimeZone::__ construct()的別名。 它接受時(shí)區(qū)字符串作為參數(shù),并創(chuàng)建一個(gè)DateTimeZone對(duì)象。

語(yǔ)法

timezone_open($timezone)

參數(shù)

序號(hào)參數(shù)及說(shuō)明
1

timezone (必需)

這是表示時(shí)區(qū)的字符串值。

返回值

timezone_name_get()函數(shù)返回DateTimeZone對(duì)象。如果失敗,則此函數(shù)返回布爾值false

PHP版本

此函數(shù)最初是在PHP版本5.2.0中引入的,并且可以在所有更高版本中使用。

在線示例

以下示例演示了timezone_open()函數(shù)的用法-

<?php
   $tz = "Indian/mahe";
   $res = timezone_open($tz);   
   print_r($res);
?>
測(cè)試看看?/?

輸出結(jié)果

DateTimeZone Object
(
  [timezone_type] => 3
  [timezone] => Indian/mahe
)

在線示例

創(chuàng)建一個(gè)新的 DateTimeZone 對(duì)象,然后返回時(shí)區(qū)的名稱:

<?php
$dateSrc = '2017-06-25 1:50 GMT';
$dateTime = date_create( $dateSrc);
   
$DateTimeZone = timezone_open ( 'America/Chicago' );
date_timezone_set( $dateTime, $DateTimeZone );
$NewDateTimeZone = date_timezone_get($dateTime);
   
echo '新時(shí)區(qū)為 '. timezone_name_get($NewDateTimeZone);
echo "\n";

# 使用第二種方法
$dateTime = new DateTime($dateSrc);
   
$DateTimeZone = new DateTimeZone( 'America/Chicago' );
$dateTime->setTimezone( $DateTimeZone );
$NewDateTimeZone = $dateTime->getTimezone ();
   
echo '新時(shí)區(qū)為 '. timezone_name_get ($NewDateTimeZone);
?>
測(cè)試看看?/?

輸出結(jié)果:

新時(shí)區(qū)為 America/Chicago
新時(shí)區(qū)為 America/Chicago