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


PHP IntlCalendar get()用法及代碼示例


IntlCalendar::get()函數是PHP中的內置函數,用於獲取特定字段的值。

用法:

  • 麵向對象的風格
    int IntlCalendar::get( int $field )
  • 程序風格
    int intlcal_get( IntlCalendar $cal, int $field )

參數:此函數使用上麵提到和下麵描述的兩個參數:


  • $cal:此參數保存IntlCalendar的資源。
  • $field:此參數保存IntlCalendar日期/時間字段常量之一。該字段包含一個介於0到IntlCalendar::FIELD_COUNT之間的整數值。

返回值:該函數返回保存時間字段值的整數。

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

程序:

<?php 
  
// Set the DateTime zone 
ini_set('date.timezone', 'Asia/Calcutta'); 
  
// Declare the IntlCalendar class 
$cls = new ReflectionClass('IntlCalendar'); 
  
// Declare an empty array 
$arr = array(); 
  
// Loop for IntlCalendar constants 
foreach ($cls->getConstants() as $constName => $constVal) { 
    $arr[$constVal] = $constName; 
} 
  
// Create an instance of IntlCalendar 
$calendar = IntlCalendar::createInstance(); 
  
// Display the date object 
var_dump(IntlDateFormatter::formatObject($calendar)); 
  
// Loop to display result 
foreach ($arr as $constVal => $constName) { 
    echo "Constant Name: " . $constName .  
    "\nConstant Value: " . $calendar->get($constVal) . "\n\n"; 
} 
  
?>
輸出:
string(25) "Sep 23, 2019, 11:03:29 AM"
Constant Name: WALLTIME_LAST
Constant Value: 1

Constant Name: WALLTIME_FIRST
Constant Value: 2019

Constant Name: WALLTIME_NEXT_VALID
Constant Value: 8

Constant Name: DOW_TYPE_WEEKEND_CEASE
Constant Value: 39

Constant Name: DOW_WEDNESDAY
Constant Value: 4

Constant Name: DOW_THURSDAY
Constant Value: 23

Constant Name: DOW_FRIDAY
Constant Value: 266

Constant Name: DOW_SATURDAY
Constant Value: 2

Constant Name: FIELD_DAY_OF_WEEK_IN_MONTH
Constant Value: 4

Constant Name: FIELD_AM_PM
Constant Value: 0

Constant Name: FIELD_HOUR
Constant Value: 11

Constant Name: FIELD_HOUR_OF_DAY
Constant Value: 11

Constant Name: FIELD_MINUTE
Constant Value: 3

Constant Name: FIELD_SECOND
Constant Value: 29

Constant Name: FIELD_MILLISECOND
Constant Value: 939

Constant Name: FIELD_ZONE_OFFSET
Constant Value: 19800000

Constant Name: FIELD_DST_OFFSET
Constant Value: 0

Constant Name: FIELD_YEAR_WOY
Constant Value: 2019

Constant Name: FIELD_DOW_LOCAL
Constant Value: 2

Constant Name: FIELD_EXTENDED_YEAR
Constant Value: 2019

Constant Name: FIELD_JULIAN_DAY
Constant Value: 2458750

Constant Name: FIELD_MILLISECONDS_IN_DAY
Constant Value: 39809939

Constant Name: FIELD_IS_LEAP_MONTH
Constant Value: 0

Constant Name: FIELD_FIELD_COUNT
Constant Value:

參考: https://www.php.net/manual/en/intlcalendar.get.php



相關用法


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