PHP | IntlCalendar get() Function

The IntlCalendar::get() function is an inbuilt function in PHP which is used to get the value for a specific field.

Syntax:

  • Object oriented style
    int IntlCalendar::get( int $field )
  • Procedural style
    int intlcal_get( IntlCalendar $cal, int $field )

Parameters: This function uses two parameters as mentioned above and described below:



  • $cal: This parameter holds the resource of IntlCalendar.
  • $field: This parameter holds one of the IntlCalendar date/time field constants. This field contains an integer value lies between 0 to IntlCalendar::FIELD_COUNT.

Return Value: This function returns the integer which holds the value of time field.

Below program illustrates the IntlCalendar::get() function in PHP:

Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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";
}
  
?>

chevron_right


Output:

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:

Reference: https://www.php.net/manual/en/intlcalendar.get.php

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.