<!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>Set the pattern used for the IntlDateFormatter</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="intldateformatter.setlenient.html">IntlDateFormatter::setLenient</a></div> <div class="next" style="text-align: right; float: right;"><a href="intldateformatter.settimezoneid.html">IntlDateFormatter::setTimeZoneId</a></div> <div class="up"><a href="class.intldateformatter.html">IntlDateFormatter</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="intldateformatter.setpattern" class="refentry"> <div class="refnamediv"> <h1 class="refname">IntlDateFormatter::setPattern</h1> <h1 class="refname">datefmt_set_pattern</h1> <p class="verinfo">(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)</p><p class="refpurpose"><span class="refname">IntlDateFormatter::setPattern</span> -- <span class="refname">datefmt_set_pattern</span> — <span class="dc-title">Set the pattern used for the IntlDateFormatter</span></p> </div> <div class="refsect1 description" id="refsect1-intldateformatter.setpattern-description"> <h3 class="title">Description</h3> <p class="para"> Object oriented style </p> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>IntlDateFormatter::setPattern</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span> )</div> <p class="para rdfs-comment"> Procedural style </p> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>datefmt_set_pattern</strong></span> ( <span class="methodparam"><span class="type"><a href="class.intldateformatter.html" class="type IntlDateFormatter">IntlDateFormatter</a></span> <code class="parameter">$fmt</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$pattern</code></span> )</div> <p class="para rdfs-comment"> Set the pattern used for the IntlDateFormatter. </p> </div> <div class="refsect1 parameters" id="refsect1-intldateformatter.setpattern-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">fmt</code></em></span> <dd> <p class="para"> The formatter resource. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">pattern</code></em></span> <dd> <p class="para"> New pattern string to use. Possible patterns are documented at <a href="http://userguide.icu-project.org/formatparse/datetime" class="link external">» http://userguide.icu-project.org/formatparse/datetime</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-intldateformatter.setpattern-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. Bad formatstrings are usually the cause of the failure. </p> </div> <div class="refsect1 examples" id="refsect1-intldateformatter.setpattern-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-2660"> <p><strong>Example #1 <span class="function"><strong>datefmt_set_pattern()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$fmt </span><span style="color: #007700">= </span><span style="color: #0000BB">datefmt_create</span><span style="color: #007700">(<br /> </span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</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 /> </span><span style="color: #DD0000">'America/Los_Angeles'</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">GREGORIAN</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'MM/dd/yyyy'<br /></span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">'pattern of the formatter is : ' </span><span style="color: #007700">. </span><span style="color: #0000BB">datefmt_get_pattern</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">'First Formatted output with pattern is ' </span><span style="color: #007700">. </span><span style="color: #0000BB">datefmt_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">datefmt_set_pattern</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #DD0000">'yyyymmdd hh:mm:ss z'</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">'Now pattern of the formatter is : ' </span><span style="color: #007700">. </span><span style="color: #0000BB">datefmt_get_pattern</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">'Second Formatted output with pattern is ' </span><span style="color: #007700">. </span><span style="color: #0000BB">datefmt_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-2661"> <p><strong>Example #2 OO example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$fmt </span><span style="color: #007700">= new </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">(<br /> </span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</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 /> </span><span style="color: #DD0000">'America/Los_Angeles'</span><span style="color: #007700">,<br /> </span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">GREGORIAN</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'MM/dd/yyyy'<br /></span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">'pattern of the formatter is : ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-></span><span style="color: #0000BB">getPattern</span><span style="color: #007700">();<br />echo </span><span style="color: #DD0000">'First Formatted output is ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-></span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-></span><span style="color: #0000BB">setPattern</span><span style="color: #007700">(</span><span style="color: #DD0000">'yyyymmdd hh:mm:ss z'</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">'Now pattern of the formatter is : ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-></span><span style="color: #0000BB">getPattern</span><span style="color: #007700">();<br />echo </span><span style="color: #DD0000">'Second Formatted output is ' </span><span style="color: #007700">. </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-></span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <p class="para">The above example will output:</p> <div class="example-contents screen"> <div class="cdata"><pre> pattern of the formatter is : MM/dd/yyyy First Formatted output with pattern is 12/31/1969 Now pattern of the formatter is : yyyymmdd hh:mm:ss z Second Formatted output with pattern is 19690031 04:00:00 PST </pre></div> </div> </div> <div class="refsect1 seealso" id="refsect1-intldateformatter.setpattern-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="intldateformatter.getpattern.html" class="function" rel="rdfs-seeAlso">datefmt_get_pattern()</a> - Get the pattern used for the IntlDateFormatter</span></li> <li class="member"> <span class="function"><a href="intldateformatter.create.html" class="function" rel="rdfs-seeAlso">datefmt_create()</a> - Create a date formatter</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="intldateformatter.setlenient.html">IntlDateFormatter::setLenient</a></div> <div class="next" style="text-align: right; float: right;"><a href="intldateformatter.settimezoneid.html">IntlDateFormatter::setTimeZoneId</a></div> <div class="up"><a href="class.intldateformatter.html">IntlDateFormatter</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>