PHP | IntlCalendar setTime() Function

The IntlCalendar::setTime() function is an inbuilt function in PHP which is used to set the calendar time object in terms of milliseconds since the epoch. The calendar time instant is represented by the float and its value should be an integer number of milliseconds since the epoch (1 Jan 1970 00:00:00.000 UTC). It ignores the leap second.

Syntax:

  • Object oriented style
    bool IntlCalendar::setTime( float $date )
  • Procedural style
    bool intlcal_set_time( IntlCalendar $cal, float $date )

Parameters: This function uses two parameters as mentioned above and described below:



  • $cal: This parameter holds the resource of IntlCalendar.
  • $date: This parameter holds the instant represented by the number of number of milliseconds between the instant and the epoch time. It is ignoring leap seconds.

Return Value: This function returns TRUE on success and FALSE on failure.

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

Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Set the date timezone
ini_set('date.timezone', 'Asia/Calcutta');
  
// Create a DateTime object
$cal = IntlCalendar::fromDateTime('2019-03-21 09:19:29');
  
// Format the DateTime object 
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
  
// Declare a new IntlGregorianCalendar object
$cal = new IntlGregorianCalendar(2019, 8, 22, 10, 30, 34);
  
// Format the DateTime object 
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
  
// Set the DateTime object
$cal->setTime(strtotime('2019-10-27 -05:30:00 GMT') * 1000);
  
// Format the DateTime object 
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL);
  
?>

chevron_right


Output:

Thursday, March 21, 2019 at 9:19:29 AM India Standard Time
Sunday, September 22, 2019 at 10:30:34 AM India Standard Time
Thursday, January 1, 1970 at 5:30:00 AM India Standard Time

Reference: https://www.php.net/manual/en/intlcalendar.settime.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.