Syntax: Parameters:This function takes one parameter,
$dateTime,which contains a DateTime object or a string that can be passed to the DateTime::__ construct() function.
Return Value:This function returns an IntlCalendar object on success, or NULL on error. If a string is passed as a parameter, an exception is thrown inside the DateTime constructor.The programs below illustrate the IntlCalendar::fromDateTime() function in PHP:
Program 1:
// Create IntlCalendar from a DateTime object or string
$calendar
= IntlCalendar::fromDateTime (
’2019-08-29 09: 19: 29’
);
// Add date
$calendar
-> add (IntlCalendar::FIELD_YEAR, 5);
// Show result date
echo
IntlDateFormatter::formatObject (
$calendar
),
""
;
// Add date
$calendar
-> add (IntlCalendar::FIELD_YEAR, 10);
// Display the output
echo
IntlDateFormatter::formatObject (
$calendar
),
""
;
// Add date
$calendar
-> add (IntlCalendar::FIELD_HOUR_OF_DAY, 10);
// Display the output
echo
IntlDateFormatter::formatObject (
$calendar
);
?>
Exit:Aug 29, 2024, 9:19:29 AM Aug 29, 2034, 9:19:29 AM Aug 29, 2034, 7:19:29 PM
Program 2:
// Create IntlCalendar from a DateTime object or string
$calendar
= IntlCalendar: : fromDateTime (
’2019-08-29 09: 19: 29’
);
// Add date
$calendar
-> add (IntlCalendar::FIELD_MONTH, 1);
// Show result date
echo
IntlDateFormatter::formatObject (
$calendar
);
?>
Exit:Sep 29, 2019, 9:19:29 AM
Link: https://www.php.net/manual/en/intlcalendar.fromdatetime.php