- Object Oriented Style:
string IntlDateFormatter::formatObject (object $object, mixed $format = NULL, string $locale = NULL)
- Procedural style:
string datefmt_format_object (object $object, mixed $format = NULL, string $locale = NULL)
- object:this parameter contains an object of type IntlCalendar or DateTime.
- format:this parameter contains a date format for setting the date in the specified format. An array with two values can be used (the first sets the date style, and the second sets the time style. The constants are IntlDateFormatter::NONE, IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM, IntlDateFormatter::LONG, IntlDateFormatter::FULL), integer or string format ... NULL is used for the default style.
- locale:This parameter contains the locale to use. NULL is used for the default locale.
// Set time zone and locale
ini_set
(
’date.timezone’
,
’Asia / Calcutta’
);
ini_set
(
’intl.default_locale’
,
’en_US’
);
// Create an IntlCalendar from a DateTime object or string
$calander
= IntlCalendar::fromDateTime (
’2019-10 -05 09: 19: 29’
);
// Display the date in the specified format
echo
"Default date format = >"
.
IntlDateFormatter::formatObject (
$calander
).
""
;
// Display the date in the specified format
echo
"Date in string format = >"
.
IntlDateFormatter::formatObject (
$calander
,
"dd MM yyyy "
).
""
;
// Display the date in the specified format
echo
"Date in long format = >"
.
IntlDateFormatter::formatObject (
$calander
,
IntlDateFormatter::TRADITIONAL ).
""
;
// Display the date in the specified format
echo
"Date in array format = >"
,
IntlDateFormatter::formatObject (
$calander
,
array
(
IntlDateFormatter::NONE,
IntlDateFormatter::FULL)
);
?>
Exit:Default date format = > Oct 5, 2019, 9:19:29 AM Date in string format = > 05 10 2019 Date in long format = > Saturday, October 5, 2019 at 9:19:29 AM India Standard Time Date in array format = > 9:19:29 AM India Standard Time
Link: https : //www.php.net/manual/en/intldateformatter.formatobject.php