Open In App

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:



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:




<?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());
  
?>

Output:
float(1569306894500)
float(1571747456000)
float(1553159969000)
float(1553159969000)

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

Article Tags :