PHP | IntlDateFormatter getDateType() Function
The IntlDateFormatter::getDateType() function is an inbuilt function in PHP which is used to get the datetype used for the IntlDateFormatter object.
Syntax:
Parameters: This function uses single parameter $fmt which holds the resource of formatter.
Return Value: This function returns the current date type value of the formatter.
Below programs illustrate the IntlDateFormatter::getDateType() function in PHP:
Program 1:
<?php
$formatter = datefmt_create(
'en_US' ,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Kolkata' ,
IntlDateFormatter::TRADITIONAL,
"MM/dd/yyyy"
);
echo 'Calendar of formatter: '
. datefmt_get_datetype( $formatter ) . "\n" ;
echo "Formatted calendar output: "
. datefmt_format( $formatter , 0) . "\n\n" ;
$formatter = datefmt_create(
'en_US' ,
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Asia/Kolkata' ,
IntlDateFormatter::TRADITIONAL
);
echo 'Calendar of formatter: '
. datefmt_get_datetype( $formatter ) . "\n" ;
echo "Formatted calendar output: "
. datefmt_format( $formatter , 0);
?>
|
Output:
Calendar of formatter: 0
Formatted calendar output: 01/01/1970
Calendar of formatter: 3
Formatted calendar output: 1/1/70, 5:30 AM
Program 2:
<?php
$formatter = datefmt_create(
'en_US' ,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Kolkata' ,
IntlDateFormatter::TRADITIONAL,
"MM/dd/yyyy"
);
echo 'Calendar of formatter: '
. $formatter ->getDateType() . "\n" ;
echo "Formatted calendar output: "
. $formatter ->format(0) . "\n\n" ;
$formatter = datefmt_create(
'en_US' ,
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Asia/Kolkata' ,
IntlDateFormatter::TRADITIONAL
);
echo 'Calendar of formatter: '
. $formatter ->getDateType() . "\n" ;
echo "Formatted calendar output: "
. $formatter ->format(0);
?>
|
Output:
Calendar of formatter: 0
Formatted calendar output: 01/01/1970
Calendar of formatter: 3
Formatted calendar output: 1/1/70, 5:30 AM
Reference: https://www.php.net/manual/en/intldateformatter.getdatetype.php
Last Updated :
10 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...