Sunday, November 23, 2025
HomeLanguagesPHP | IntlDateFormatter getCalendar() Function

PHP | IntlDateFormatter getCalendar() Function

The IntlDateFormatter::getCalendar() function is an inbuilt function in PHP which is used to return the calendar type used for the IntlDateFormatter object.
Syntax: 
 

  • Object oriented style: 
     
int IntlDateFormatter::getCalendar( void )
  • Procedural style: 
     
int datefmt_get_calendar( IntlDateFormatter $fmt )

Parameters: This function accepts single parameter $fmt which holds the resource of formatter.
Return Value: This function returns the calendar type which is used by the formatter. The formatter object are either IntlDateFormatter::TRADITIONAL or IntlDateFormatter::GREGORIAN.
Below programs illustrate the IntlDateFormatter::getCalendar() function in PHP:
Program 1: 
 

php




<?php
 
// Create a date formatter
$formatter = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'Asia/Kolkata',
    IntlDateFormatter::TRADITIONAL,
    "MM/dd/yyyy"
);
 
// Get the calendar type
echo 'Calendar of formatter: '
        . datefmt_get_calendar($formatter) . "\n";
 
// Get the format of date/time value as a string
echo "Formatted calendar output: "
        . datefmt_format( $formatter , 0) . "\n\n";
 
// Set the calendar type used by the formatter
datefmt_set_calendar($formatter,
        IntlDateFormatter::GREGORIAN);
 
// Get the calendar type
echo 'Calendar of formatter: '
        . datefmt_get_calendar($formatter) . "\n";
 
// Get the format of date/time value as a string
echo "First Formatted output is "
        . datefmt_format( $formatter , 0);
 
?>


Output: 

Calendar of formatter: 0
Formatted calendar output: 01/01/1970

Calendar of formatter: 1
First Formatted output is 01/01/1970

 

Program 2: 
 

php




<?php
 
// Create a date formatter
$formatter = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'Asia/Kolkata',
    IntlDateFormatter::TRADITIONAL,
    "MM/dd/yyyy"
);
 
// Get the calendar type
echo 'Calendar of formatter: '
        . $formatter->getCalendar() . "\n";
 
// Get the format of date/time value as a string
echo "Formatted calendar output: "
        . $formatter->format(0) . "\n\n";
 
// Set the calendar type used by the formatter
$formatter->setCalendar(IntlDateFormatter::GREGORIAN);
 
// Get the calendar type
echo 'Calendar of formatter: '
        . $formatter->getCalendar() . "\n";
 
// Get the format of date/time value as a string
echo "First Formatted output is "
        . $formatter->format(0);
 
?>


Output: 

Calendar of formatter: 0
Formatted calendar output: 01/01/1970

Calendar of formatter: 1
First Formatted output is 01/01/1970

 

Reference: https://www.php.net/manual/en/intldateformatter.getcalendar.php
 

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6864 POSTS0 COMMENTS
Umr Jansen
6852 POSTS0 COMMENTS