Skip to content
Related Articles

Related Articles

PHP | IntlCalendar createInstance() Function
  • Last Updated : 29 Aug, 2019

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

Syntax:

  • Object oriented style:
    IntlCalendar IntlCalendar::createInstance( mixed $timeZone = NULL, string $locale = "" )
  • Procedural style:
    IntlCalendar intlcal_create_instance( mixed $timeZone = NULL, string $locale = "" )

Parameters:

  • $timeZone: This parameter holds the used timezone.
    • NULL: It is the default timezone.
    • IntlTimeZone: It is used directly.
    • DateTimeZone: It allows to set the timzone in DateTimeZone format. The identifier of DateTimeZone will be extracted and an ICU timezone object will be created.
    • string: It is a valid ICU timezone identifier.
  • $locale: This parameter holds the locale to use or NULL to use the default locale.

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

bool(false)
bool(true)
bool(true)
bool(false)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

bool(true)

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :