Syntax: Parameters:This function takes one parameter,
$cal,which contains the IntlCalendar object resource.
Return value:this function returns a DateTime object with the same time zone as this object and the same time, except for less precision on success, and returns FALSE on error.The following program illustrates the IntlCalendar function: : toDateTime() in PHP:
Program :
// Set the DateTime zone
ini_set
(
’date.timezone’
,
’Asia / Calcutta’
);
ini_set
(
’date.timezone’
,
’UTC’
);
// Create an IntlCalendar instance
$calendar
= IntlCalendar::createInstance (
’Asia / Calcutta’
);
// Convert IntlCalendar to DateTime
$datetime
=
$calendar
-> toDateTime();
// Display the DateTime object
var_dump (
$datetime
);
// Declare IntlGregorianCalendar
$calendar
=
new
IntlGregorianCalendar (2019, 9, 22, 12, 40, 0);
// Convert IntlGregorianCalendar to
// DateTime object
$datetime
=
$calendar
-> toDateTime();
// Display the DateTime object
var_dump (
$datetime
);
?>
Exit:object (DateTime ) # 3 (3) {["date"] = > string (26) "2019-09-25 11: 15: 33.000000" ["timezone_type"] = > int (3) ["timezone"] = > string (13) "Asia / Calcutta"} object (DateTime) # 4 (3) {["date"] = > string (26) "2019-10-22 12: 40: 00.000000" ["timezone_type"] = > int (3) ["timezone"] = > string (3) "UTC"}
Link: https://www.php.net/manual/en/intlcalendar.todatetime.php