Open In App

PHP | IntlCalendar createInstance() Function

The IntlCalendar::createInstance() function is an inbuilt function in PHP which is used to create an instance of IntlCalendar.

Syntax:



Parameters:

Return Value: This function creates an IntlCalendar instance on success or NULL on failure.



Below programs illustrate the IntlCalendar::createInstance() function in PHP:

Program 1:




<?php
 
// Create an IntlCalendar instance
$calendar1 = IntlCalendar::createInstance();
 
// Create an IntlCalendar from a DateTime object or string
$calendar2 = IntlCalendar::fromDateTime('2019-03-21 09:19:29');
 
// Use IntlCalendar::before() function
var_dump($calendar1->before($calendar2));
var_dump($calendar2->before($calendar1));
 
// Use IntlCalendar::before() function
var_dump($calendar1->after($calendar2));
var_dump($calendar2->after($calendar1));
         
?>

Output:
bool(false)
bool(true)
bool(true)
bool(false)

Program 2:




<?php
 
// Create an IntlCalendar from a DateTime object or string
$calendar1 = IntlCalendar::fromDateTime('2019-03-21 09:19:29');
 
// Create an instance of IntlCalendar
$calendar2 = IntlCalendar::createInstance(NULL, 'en_US');
 
// Set DateTime of $calendar2 to $calendar1
$calendar2->setTime($calendar1->getTime());
 
// Use IntlCalendar::equals() function to cCompare time
// of two IntlCalendar objects and display result
var_dump($calendar1->equals($calendar2));
         
?>

Output:
bool(true)

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


Article Tags :