PHP | IntlCalendar fromDateTime() Function
The IntlCalendar::fromDateTime() function is an inbuilt function in PHP which is used to create an IntlCalendar from a DateTime object or string. The value of new calendar represents the same instant as the DateTime and timezone.
Syntax:
Parameters: This function accepts single parameter $dateTime which holds the DateTime object or a string that can be passed to DateTime::__construct() function.
Return Value: This function returns the IntlCalendar object on success or NULL on failure. If a string is passed as a parameter then an exception occurs inside the DateTime constructor.
Below programs illustrate the IntlCalendar::fromDateTime() function in PHP:
Program 1:
<?php
$calendar = IntlCalendar::fromDateTime( '2019-08-29 09:19:29' );
$calendar ->add(IntlCalendar::FIELD_YEAR, 5);
echo IntlDateFormatter::formatObject( $calendar ), "\n" ;
$calendar ->add(IntlCalendar::FIELD_YEAR, 10);
echo IntlDateFormatter::formatObject( $calendar ), "\n" ;
$calendar ->add(IntlCalendar::FIELD_HOUR_OF_DAY, 10);
echo IntlDateFormatter::formatObject( $calendar );
?>
|
Output:
Aug 29, 2024, 9:19:29 AM
Aug 29, 2034, 9:19:29 AM
Aug 29, 2034, 7:19:29 PM
Program 2:
<?php
$calendar = IntlCalendar::fromDateTime( '2019-08-29 09:19:29' );
$calendar ->add(IntlCalendar::FIELD_MONTH, 1);
echo IntlDateFormatter::formatObject( $calendar );
?>
|
Output:
Sep 29, 2019, 9:19:29 AM
Reference: https://www.php.net/manual/en/intlcalendar.fromdatetime.php
Last Updated :
25 Sep, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...