當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP timezone_transitions_get()用法及代碼示例


timezone_transitions_get()函數是PHP中的內置函數,用於返回時區的所有轉換。此函數返回一個數組,其中包含成功時所有轉換的關聯數組或失敗時為False的關聯數組。

用法:

  • 程序風格:
    timezone_transitions_get( $object, $timestamp_begin, $timestamp_end )
  • 麵向對象的樣式:
    DateTimeZone::getTransitions( $timestamp_begin, $timestamp_end )

參數:此函數接受上述和以下所述的三個參數:


  • $object:它是必需參數,用於指定date_create()函數返回的DateTime對象。
  • $timestamp_begin:此參數用於設置開始時間戳。
  • $timestamp_end:此參數用於設置結束時間戳記。

返回值:此函數返回一個包含關聯數組的數組,該數組在成功時會發生所有轉換,而失敗時會發生False。

以下示例程序旨在說明PHP中的timezone_transitions_get()函數:

程序1:

<?php 
   
// Set time_zone object 
$time_zone = timezone_open('Asia/Kolkata'); 
   
// Set the transition of time_zone 
$transition = timezone_transitions_get( $time_zone ); 
  
// Display an array containing associative 
// array of all transition 
print_r(array_slice($transition, 0, 3)); 
?>
輸出:
Array
(
    [0] => Array
        (
            [ts] => -9223372036854775808
            [time] => -292277022657-01-27T08:29:52+0000
            [offset] => 21200
            [isdst] => 
            [abbr] => HMT
        )

    [1] => Array
        (
            [ts] => -2147483648
            [time] => 1901-12-13T20:45:52+0000
            [offset] => 19270
            [isdst] => 
            [abbr] => MMT
        )

    [2] => Array
        (
            [ts] => -2019705670
            [time] => 1905-12-31T18:38:50+0000
            [offset] => 19800
            [isdst] => 
            [abbr] => IST
        )

)

程序2:

<?php 
  
// Set time_zone object 
$timezone = new DateTimeZone("Asia/Kolkata"); 
  
// Set the transition of time_zone 
$transition = $timezone->getTransitions(); 
  
// Display an array containing associative 
// array of all transition 
print_r(array_slice($transition, 0, 3)); 
?>
輸出:
Array
(
    [0] => Array
        (
            [ts] => -9223372036854775808
            [time] => -292277022657-01-27T08:29:52+0000
            [offset] => 21200
            [isdst] => 
            [abbr] => HMT
        )

    [1] => Array
        (
            [ts] => -2147483648
            [time] => 1901-12-13T20:45:52+0000
            [offset] => 19270
            [isdst] => 
            [abbr] => MMT
        )

    [2] => Array
        (
            [ts] => -2019705670
            [time] => 1905-12-31T18:38:50+0000
            [offset] => 19800
            [isdst] => 
            [abbr] => IST
        )

)

相關文章:

參考: http://php.net/manual/en/datetimezone.gettransitions.php



相關用法


注:本文由純淨天空篩選整理自Mahadev99大神的英文原創作品 PHP | timezone_transitions_get() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。