mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
explain the interval format
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@287821 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
6178255c0b
commit
791c1e2460
1 changed files with 79 additions and 0 deletions
|
@ -28,12 +28,91 @@
|
|||
<para>
|
||||
Interval specification.
|
||||
</para>
|
||||
<para>
|
||||
The <emphasis>date portion</emphasis>, if any,
|
||||
starts with the letter <literal>P</literal>.
|
||||
Each date unit is represented by an integer value
|
||||
followed by the letter indicating the unit type.
|
||||
The date unit types are
|
||||
<literal>Y</literal> for years,
|
||||
<literal>M</literal> for months and
|
||||
<literal>D</literal> for days.
|
||||
For example, the format to create a two day
|
||||
interval is <literal>P2D</literal>.
|
||||
</para>
|
||||
<para>
|
||||
The <emphasis>time portion</emphasis>, if any,
|
||||
starts with the letter <literal>T</literal>.
|
||||
Each time unit is represented by an integer value
|
||||
followed by the letter indicating the unit type.
|
||||
The time unit types are
|
||||
<literal>H</literal> for hours,
|
||||
<literal>M</literal> for minutes and
|
||||
<literal>S</literal> for seconds.
|
||||
For example, the format to create a two second
|
||||
interval is <literal>T2S</literal>.
|
||||
</para>
|
||||
<para>
|
||||
The date and time portions can be combined. To
|
||||
demonstrate, an interval of six years and five minutes
|
||||
is represented by <literal>P6YT5M</literal>.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
The unit types must be entered from the largest
|
||||
scale unit on the left to the smallest scale unit
|
||||
on the right.
|
||||
So dates come before times, years before months,
|
||||
months before days, days before minutes, etc.
|
||||
So one year and four days must be
|
||||
<literal>P1Y4D</literal>, not <literal>P4D1Y</literal>.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
The format can also be entered in an ISO format.
|
||||
A sample of one year and four days would be
|
||||
<literal>P0001-00-04T00:00:00</literal>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$interval = new DateInterval('P2Y4DT6H8M');
|
||||
print_r($interval);
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen role="php">
|
||||
<![CDATA[
|
||||
DateInterval Object
|
||||
(
|
||||
[y] => 2
|
||||
[m] => 0
|
||||
[d] => 4
|
||||
[h] => 6
|
||||
[i] => 8
|
||||
[s] => 0
|
||||
[invert] => 0
|
||||
[days] => 0
|
||||
)
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
|
Loading…
Reference in a new issue