Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 8493

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Calculate difference between given time and this objectʼs time</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="intlcalendar.equals.html">IntlCalendar::equals</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="intlcalendar.fromdatetime.html">IntlCalendar::fromDateTime</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.fielddifference" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">IntlCalendar::fieldDifference</h1>
  <p class="verinfo">(PHP 5.5.0, PECL &gt;= 3.0.0a1)</p><p class="refpurpose"><span class="refname">IntlCalendar::fieldDifference</span> &mdash; <span class="dc-title">Calculate difference between given time and this objectʼs time</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-intlcalendar.fielddifference-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><strong>IntlCalendar::fieldDifference</strong></span>
    ( <span class="methodparam"><span class="type">float</span> <code class="parameter">$when</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$field</code></span>
   )</div>

  <p class="para rdfs-comment">
   Return the difference between the given time and the time this object is
   set to, with respect to the quantity specified the
   <em><code class="parameter">field</code></em> parameter.
  </p>
  <p class="para">
   This method is meant to be called successively, first with the most
   significant field of interest down to the least significant field. To this
   end, as a side effect, this calendarʼs value for the field specified is
   advanced by the amount returned.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-intlcalendar.fielddifference-parameters">
  <h3 class="title">Parameters</h3>
  <dl>

   <dt>

    <span class="term"><em><code class="parameter">when</code></em></span>
    <dd>

     <p class="para">
      The time against which to compare the quantity represented by the
      <em><code class="parameter">field</code></em>. For the result to be positive, the time
      given for this parameter must be ahead of the time of the object the
      method is being invoked on.
     </p>
    </dd>

   </dt>

   <dt>

    <span class="term"><em><code class="parameter">field</code></em></span>
    <dd>

     <p class="para">
      The field that represents the quantity being compared.
     </p>
     

<p class="para">
 One of the <a href="class.intlcalendar.html" class="classname">IntlCalendar</a> date/time <a href="class.intlcalendar.html#intlcalendar.constants" class="link">field constants</a>. These are integer
 values between <em>0</em> and
 <strong><code>IntlCalendar::FIELD_COUNT</code></strong>.
</p>

    </dd>

   </dt>

  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-intlcalendar.fielddifference-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a (signed) difference of time in the unit associated with the
   specified field or <strong><code>FALSE</code></strong> on failure.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-intlcalendar.fielddifference-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2596">
   <p><strong>Example #1  <span class="function"><strong>IntlCalendar::fieldDifference()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Europe/Lisbon'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'intl.default_locale'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'fr_FR'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$cal1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">fromDateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2012-02-29&nbsp;09:00:11'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$cal2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">fromDateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2013-03-01&nbsp;09:19:29'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$time&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$cal2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTime</span><span style="color: #007700">();<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Time&nbsp;before:&nbsp;"</span><span style="color: #007700">,&nbsp;</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">$cal1</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"The&nbsp;difference&nbsp;in&nbsp;time&nbsp;is&nbsp;%d&nbsp;year(s),&nbsp;%d&nbsp;month(s),&nbsp;"<br />&nbsp;&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"%d&nbsp;day(s),&nbsp;%d&nbsp;hour(s)&nbsp;and&nbsp;%d&nbsp;minute(s)\n"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$cal1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fieldDifference</span><span style="color: #007700">(</span><span style="color: #0000BB">$time</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">FIELD_YEAR</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$cal1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fieldDifference</span><span style="color: #007700">(</span><span style="color: #0000BB">$time</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">FIELD_MONTH</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$cal1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fieldDifference</span><span style="color: #007700">(</span><span style="color: #0000BB">$time</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">FIELD_DAY_OF_MONTH</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$cal1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fieldDifference</span><span style="color: #007700">(</span><span style="color: #0000BB">$time</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">FIELD_HOUR_OF_DAY</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$cal1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fieldDifference</span><span style="color: #007700">(</span><span style="color: #0000BB">$time</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">IntlCalendar</span><span style="color: #007700">::</span><span style="color: #0000BB">FIELD_MINUTE</span><span style="color: #007700">)<br />);<br /><br /></span><span style="color: #FF8000">//now&nbsp;it&nbsp;was&nbsp;advanced&nbsp;to&nbsp;the&nbsp;target&nbsp;time,&nbsp;exception&nbsp;for&nbsp;the&nbsp;seconds,<br />//for&nbsp;which&nbsp;we&nbsp;did&nbsp;not&nbsp;measure&nbsp;the&nbsp;difference<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Time&nbsp;after:&nbsp;"</span><span style="color: #007700">,&nbsp;</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">$cal1</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</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>
Time before: 29 févr. 2012 09:00:11
The difference in time is 1 year(s), 0 month(s), 1 day(s), 0 hour(s) and 19 minute(s)
Time after: 1 mars 2013 09:19:11
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="intlcalendar.equals.html">IntlCalendar::equals</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="intlcalendar.fromdatetime.html">IntlCalendar::fromDateTime</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>