PHP | IntlCalendar toDateTime() Function
Last Updated :
29 Mar, 2023
The IntlCalendar::toDateTime() function is an inbuilt function in PHP which is used to convert an IntlCalendar object into a DateTime object. The DateTime object represents upto second precision with error round less than 1 second.
Syntax:
DateTime IntlCalendar::toDateTime( void )
DateTime intlcal_to_date_time( IntlCalendar $cal )
Parameters: This function accepts single parameter $cal which holds the resource of IntlCalendar object.
Return Value: This function returns a DateTime object with the same timezone as this object and the same time except for the smaller precision on success and returns FALSE on failure.
Below program illustrates the IntlCalendar::toDateTime() function in PHP:
Program:
php
<?php
ini_set ( 'date.timezone' , 'Asia/Calcutta' );
ini_set ( 'date.timezone' , 'UTC' );
$calendar = IntlCalendar::createInstance( 'Asia/Calcutta' );
$datetime = $calendar ->toDateTime();
var_dump( $datetime );
$calendar = new IntlGregorianCalendar(2019, 9, 22, 12, 40, 0);
$datetime = $calendar ->toDateTime();
var_dump( $datetime );
?>
|
Output:
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"
}
Reference: https://www.php.net/manual/en/intlcalendar.todatetime.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...