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:
- Object oriented style
bool IntlCalendar::set( int $field, int $value ) or bool IntlCalendar::set( int $year, int $month, int $dayOfMonth = NULL, int $hour = NULL, int $minute = NULL, int $second = NULL )
- Procedural style
bool intlcal_set( IntlCalendar $cal, int $field, int $value ) or bool intlcal_set( IntlCalendar $cal, int $year, int $month, int $dayOfMonth = NULL, int $hour = NULL, int $minute = NULL, int $second = NULL )
Parameters: This function accepts many parameters as mentioned above and described below:
- $cal: This parameter holds the resource of IntlCalendar object.
- $field: This parameter holds one of the IntlCalendar date/time field constants. The field constants are integer values lies between 0 to IntlCalendar::FIELD_COUNT.
- $value: This parameter holds the new value of the given field.
- $year: This parameter holds the new value for IntlCalendar::FIELD_YEAR field.
- $month: This parameter holds the new value for IntlCalendar::FIELD_MONTH field.
- $dayOfMonth: This parameter holds the new value for IntlCalendar::FIELD_DAY_OF_MONTH field. The sequence of month starts from zero i.e. 0 for January, 1 for February etc.
- $hour: This parameter holds the new value for IntlCalendar::FIELD_HOUR_OF_DAY field.
- $minute: This parameter holds the new value for IntlCalendar::FIELD_MINUTE field.
- $second: This parameter holds the new value for IntlCalendar::FIELD_SECOND field.
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= newIntlGregorianCalendar(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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					


