PHP | IntlCalendar getTime() Function

The IntlCalendar::getTime() function is an inbuilt function in PHP which is used to return the time currently represented by the object. The time is expressed in terms of milliseconds since the epoch.

Syntax:

  • Object oriented style
    float IntlCalendar::getTime( void )
  • Procedural style
    float intlcal_get_time( IntlCalendar $cal )

Parameters: This function accepts single parameter $cal which holds the resource of IntlCalendar object.



Return Value: This function returns a floating point number representing the milliseconds elapsed since the epoch (1 Jan 1970 00:00:00 UTC).

Below program illustrates the IntlCalendar::getTime() function in PHP:

Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an instance of calendar
$calendar = IntlCalendar::createInstance();
  
// Get the current time
var_dump($calendar->getTime());
  
// Create a new IntlGregorianCalendar
$calendar = new IntlGregorianCalendar(2019, 9, 22, 12, 30, 56);
  
// Get the current time
var_dump($calendar->getTime());
  
// Create a DateTime object
$calendar = IntlCalendar::fromDateTime('2019-03-21 09:19:29');
  
// Get the current time
var_dump($calendar->getTime());
  
// Set the timezone
$calendar->setTimeZone('GMT+05:30');
  
// Get the current time
var_dump($calendar->getTime());
  
?>

chevron_right


Output:

float(1569306894500)
float(1571747456000)
float(1553159969000)
float(1553159969000)

Reference: https://www.php.net/manual/en/intlcalendar.gettime.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.