Open In App

PHP | IntlCalendar set() Function

The IntlCalendar::set() function is an inbuilt function in PHP which is used to set the time field or several common fields at once. The range of field value depends on the calendar. This function can not be called with exactly four parameters.

Syntax:



Parameters: This function accepts many parameters as mentioned above and described below:

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

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

Program:




<?php
  
// Set the DateTime zone
ini_set('date.timezone', 'Asia/Calcutta');
ini_set('date.timezone', 'UTC');
  
// Create an instance of IntlCalendar
$calendar = IntlCalendar::createInstance('Asia/Calcutta');
  
// Set the DateTime object
$calendar->set(2019, 8, 24);
  
// Display the calendar object
var_dump(IntlDateFormatter::formatObject($calendar));
  
// Declare a new IntlGregorianCalendar object
$calendar = new IntlGregorianCalendar(2016, 8, 24);
  
// Set the year field
$calendar->set(IntlCalendar::FIELD_YEAR, 2018);
  
// Display the calendar object
var_dump(IntlDateFormatter::formatObject($calendar));
  
?>

Output:
string(24) "Sep 24, 2019, 8:23:53 AM"
string(25) "Sep 24, 2018, 12:00:00 AM"

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

Article Tags :