<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Create a new IntlCalendar</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="intlcalendar.construct.html">IntlCalendar::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="intlcalendar.equals.html">IntlCalendar::equals</a></div> <div class="up"><a href="class.intlcalendar.html">IntlCalendar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="intlcalendar.createinstance" class="refentry"> <div class="refnamediv"> <h1 class="refname">IntlCalendar::createInstance</h1> <p class="verinfo">(PHP 5.5.0, PECL >= 3.0.0a1)</p><p class="refpurpose"><span class="refname">IntlCalendar::createInstance</span> — <span class="dc-title">Create a new IntlCalendar</span></p> </div> <div class="refsect1 description" id="refsect1-intlcalendar.createinstance-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type"><a href="class.intlcalendar.html" class="type IntlCalendar">IntlCalendar</a></span> <span class="methodname"><strong>IntlCalendar::createInstance</strong></span> ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$timeZone</code><span class="initializer"> = NULL</span></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code><span class="initializer"> = NULL</span></span> ]] )</div> <p class="para rdfs-comment"> Given a timezone and locale, this method creates an <a href="class.intlcalendar.html" class="classname">IntlCalendar</a> object. This factory method may return a subclass of <a href="class.intlcalendar.html" class="classname">IntlCalendar</a>. </p> <p class="para"> The calendar created will represent the time instance at which it was created, based on the system time. The fields can all be cleared by calling <span class="function"><strong>IntCalendar::clear()</strong></span> with no arguments. See also <span class="function"><strong>IntlGregorianCalendar::__construct()</strong></span>. </p> </div> <div class="refsect1 parameters" id="refsect1-intlcalendar.createinstance-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <span class="term"><em><code class="parameter">timeZone</code></em></span> <dd> <p class="para"> The timezone to use. </p> <ul class="itemizedlist"> <li class="listitem"> <p class="para"> <strong><code>NULL</code></strong>, in which case the default timezone will be used, as specified in the ini setting <a href="datetime.configuration.html#ini.date.timezone" class="link">date.timezone</a> or through the function <span class="function"><a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></span> and as returned by <span class="function"><a href="function.date-default-timezone-get.html" class="function">date_default_timezone_get()</a></span>. </p> </li> <li class="listitem"> <p class="para"> An <a href="class.intltimezone.html" class="classname">IntlTimeZone</a>, which will be used directly. </p> </li> <li class="listitem"> <p class="para"> A <a href="class.datetimezone.html" class="classname">DateTimeZone</a>. Its identifier will be extracted and an ICU timezone object will be created; the timezone will be backed by ICUʼs database, not PHPʼs. </p> </li> <li class="listitem"> <p class="para"> A <span class="type"><a href="language.types.string.html" class="type string">string</a></span>, which should be a valid ICU timezone identifier. See <span class="function"><strong>IntlTimeZone::createTimeZoneIDEnumeration()</strong></span>. Raw offsets such as <em>"GMT+08:30"</em> are also accepted. </p> </li> </ul> </dd> </dt> <dt> <span class="term"><em><code class="parameter">locale</code></em></span> <dd> <p class="para"> A locale to use or <strong><code>NULL</code></strong> to use <a href="intl.configuration.html#ini.intl.default-locale" class="link">the default locale</a>. </p> </dd> </dt> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-intlcalendar.createinstance-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The created <a href="class.intlcalendar.html" class="classname">IntlCalendar</a> instance or <strong><code>NULL</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-intlcalendar.createinstance-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2594"> <p><strong>Example #1 <span class="function"><strong>IntlCalendar::createInstance()</strong></span></strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'intl.default_locale'</span><span style="color: #007700">, </span><span style="color: #DD0000">'es_ES'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Europe/Madrid'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$cal </span><span style="color: #007700">= </span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">createInstance</span><span style="color: #007700">();<br />echo </span><span style="color: #DD0000">"No arguments\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">),<br /> </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">formatObject</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">, </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">));<br />echo </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #DD0000">"Explicit timezone\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$cal </span><span style="color: #007700">= </span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">createInstance</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlTimeZone</span><span style="color: #007700">::</span><span style="color: #0000BB">getGMT</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">),<br /> </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">formatObject</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">, </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">));<br />echo </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #DD0000">"Explicit locale (with calendar)\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$cal </span><span style="color: #007700">= </span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">createInstance</span><span style="color: #007700">(</span><span style="color: #0000BB">NULL</span><span style="color: #007700">, </span><span style="color: #DD0000">'es_ES@calendar=persian'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">),<br /> </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">formatObject</span><span style="color: #007700">(</span><span style="color: #0000BB">$cal</span><span style="color: #007700">, </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">));</span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> No arguments string(21) "IntlGregorianCalendar" string(68) "martes 18 de junio de 2013 14:11:02 Hora de verano de Europa Central" Explicit timezone string(21) "IntlGregorianCalendar" string(45) "martes 18 de junio de 2013 12:11:02 GMT+00:00" Explicit locale (with calendar) string(12) "IntlCalendar" string(70) "martes 28 de Khordad de 1392 14:11:02 Hora de verano de Europa Central" </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-intlcalendar.createinstance-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><strong>IntlGregorianCalendar::__construct()</strong></span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="intlcalendar.construct.html">IntlCalendar::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="intlcalendar.equals.html">IntlCalendar::equals</a></div> <div class="up"><a href="class.intlcalendar.html">IntlCalendar</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>