downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/class.datetime.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/book.datetime.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'class.datetime.php',
   
1 => 'DateTime',
  ),
 
'up' =>
  array (
   
0 => 'book.datetime.php',
   
1 => 'Date and Time',
  ),
 
'prev' =>
  array (
   
0 => 'timezones.others.php',
   
1 => 'Others',
  ),
 
'next' =>
  array (
   
0 => 'datetime.add.php',
   
1 => 'DateTime::add',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div>

 <h1 class="title">The DateTime class</h1>
 

 <div class="partintro">


  <div id="datetime.intro" class="section">
   <h2 class="title">Introduction</h2>
   <p class="para">
    Representation of date and time.
   </p>
  </div>


  <div id="datetime.synopsis" class="section">
   <h2 class="title">Class synopsis</h2>


   <div class="classsynopsis">
    <div class="ooclass"><b class="classname">DateTime</b></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <b class="classname">DateTime</b>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.atom">DateTime::ATOM</a></var>
     <span class="initializer"> = Y-m-d\TH:i:sP</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.cookie">DateTime::COOKIE</a></var>
     <span class="initializer"> = l, d-M-y H:i:s T</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.iso8601">DateTime::ISO8601</a></var>
     <span class="initializer"> = Y-m-d\TH:i:sO</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.rfc822">DateTime::RFC822</a></var>
     <span class="initializer"> = D, d M y H:i:s O</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.rfc850">DateTime::RFC850</a></var>
     <span class="initializer"> = l, d-M-y H:i:s T</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.rfc1036">DateTime::RFC1036</a></var>
     <span class="initializer"> = D, d M y H:i:s O</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.rfc1123">DateTime::RFC1123</a></var>
     <span class="initializer"> = D, d M Y H:i:s O</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.rfc2822">DateTime::RFC2822</a></var>
     <span class="initializer"> = D, d M Y H:i:s O</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.rfc3339">DateTime::RFC3339</a></var>
     <span class="initializer"> = Y-m-d\TH:i:sP</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.rss">DateTime::RSS</a></var>
     <span class="initializer"> = D, d M Y H:i:s O</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">string</span>
      <var class="fieldsynopsis_varname"><a href="class.datetime.php#datetime.constants.w3c">DateTime::W3C</a></var>
     <span class="initializer"> = Y-m-d\TH:i:sP</span>
    ;</div>

   
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.add.php" class="function">add</a></span>
    ( <span class="methodparam"><span class="type"><a href="class.dateinterval.php" class="type DateInterval">DateInterval</a></span> <tt class="parameter">$interval</tt></span>
   )</div>
<div class="methodsynopsis dc-description">
    <span class="methodname"><a href="datetime.construct.php" class="function">__construct</a></span>
    ([ <span class="methodparam"><span class="type">string</span> <tt class="parameter">$time</tt><span class="initializer"> = &quot;now&quot;</span></span>
   [, <span class="methodparam"><span class="type"><a href="class.datetimezone.php" class="type DateTimeZone">DateTimeZone</a></span> <tt class="parameter">$timezone</tt><span class="initializer"> = NULL</span></span>
  ]] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.createfromformat.php" class="function">createFromFormat</a></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$format</tt></span>
   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$time</tt></span>
   [, <span class="methodparam"><span class="type"><a href="class.datetimezone.php" class="type DateTimeZone">DateTimeZone</a></span> <tt class="parameter">$timezone</tt></span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateInterval</span> <span class="methodname"><a href="datetime.diff.php" class="function">diff</a></span>
    ( <span class="methodparam"><span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span> <tt class="parameter">$datetime</tt></span>
   [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$absolute</tt></span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><a href="datetime.format.php" class="function">format</a></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$format</tt></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">array</span> <span class="methodname"><a href="datetime.getlasterrors.php" class="function">getLastErrors</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><a href="datetime.getoffset.php" class="function">getOffset</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><a href="datetime.gettimestamp.php" class="function">getTimestamp</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTimeZone</span> <span class="methodname"><a href="datetime.gettimezone.php" class="function">getTimezone</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.modify.php" class="function">modify</a></span>
    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$modify</tt></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.set-state.php" class="function">__set_state</a></span>
    ( <span class="methodparam"><span class="type">array</span> <tt class="parameter">$array</tt></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.setdate.php" class="function">setDate</a></span>
    ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$year</tt></span>
   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$month</tt></span>
   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$day</tt></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.setisodate.php" class="function">setISODate</a></span>
    ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$year</tt></span>
   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$week</tt></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$day</tt></span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.settime.php" class="function">setTime</a></span>
    ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$hour</tt></span>
   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$minute</tt></span>
   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$second</tt></span>
  ] )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.settimestamp.php" class="function">setTimestamp</a></span>
    ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$unixtimestamp</tt></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.settimezone.php" class="function">setTimezone</a></span>
    ( <span class="methodparam"><span class="type"><a href="class.datetimezone.php" class="type DateTimeZone">DateTimeZone</a></span> <tt class="parameter">$timezone</tt></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.sub.php" class="function">sub</a></span>
    ( <span class="methodparam"><span class="type"><a href="class.dateinterval.php" class="type DateInterval">DateInterval</a></span> <tt class="parameter">$interval</tt></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">DateTime</span> <span class="methodname"><a href="datetime.wakeup.php" class="function">__wakeup</a></span>
    ( <span class="methodparam">void</span>
   )</div>

   }</div>


  </div>
 

  <div class="section">
   <h2 class="title">Predefined Constants</h2>
   <div id="datetime.constants.types" class="section">
    <h2 class="title">DateTime Node Types</h2>
    <dl>


     <dt id="datetime.constants.atom" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::ATOM</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_ATOM</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        Atom (example: 2005-08-15T15:52:01+00:00)
       </span>
      </dd>

    

     <dt id="datetime.constants.cookie" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::COOKIE</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_COOKIE</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        HTTP Cookies (example: Monday, 15-Aug-05 15:52:01 UTC)
       </span>
      </dd>

    

     <dt id="datetime.constants.iso8601" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::ISO8601</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_ISO8601</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        ISO-8601 (example: 2005-08-15T15:52:01+0000)
       </span>
      </dd>

    

     <dt id="datetime.constants.rfc822" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::RFC822</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_RFC822</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000)
       </span>
      </dd>

    

     <dt id="datetime.constants.rfc850" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::RFC850</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_RFC850</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        RFC 850 (example: Monday, 15-Aug-05 15:52:01 UTC)
       </span>
      </dd>

    

     <dt id="datetime.constants.rfc1036" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::RFC1036</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_RFC1036</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        RFC 1036 (example: Mon, 15 Aug 05 15:52:01 +0000)
       </span>
      </dd>

    

     <dt id="datetime.constants.rfc1123" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::RFC1123</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_RFC1123</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        RFC 1123 (example: Mon, 15 Aug 2005 15:52:01 +0000)
       </span>
      </dd>

    

     <dt id="datetime.constants.rfc2822" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::RFC2822</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_RFC2822</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        RFC 2822 (Mon, 15 Aug 2005 15:52:01 +0000)
       </span>
      </dd>

    

     <dt id="datetime.constants.rfc3339" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::RFC3339</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_RFC3339</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        Same as <b><tt class="constant">DATE_ATOM</tt></b> (since PHP 5.1.3)
       </span>
      </dd>

    

     <dt id="datetime.constants.rss" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::RSS</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_RSS</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        RSS (Mon, 15 Aug 2005 15:52:01 +0000)
       </span>
      </dd>

    

     <dt id="datetime.constants.w3c" class="varlistentry">
      <span class="term"><b><tt class="constant">DateTime::W3C</tt></b></span>

      <br /><span class="term"><b><tt class="constant">DATE_W3C</tt></b></span>

      </dt><dd class="listitem">

       <span class="simpara">
        World Wide Web Consortium (example: 2005-08-15T15:52:01+00:00)
       </span>
      </dd>

    

    </dl>

   </div>
  </div>



 </div>

 































































































































<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="datetime.add.php">DateTime::add</a> — Adds an amount of days, months, years, hours, minutes and seconds to a
   DateTime object</li><li><a href="datetime.construct.php">DateTime::__construct</a> — Returns new DateTime object</li><li><a href="datetime.createfromformat.php">DateTime::createFromFormat</a> — Returns new DateTime object formatted according to the specified format</li><li><a href="datetime.diff.php">DateTime::diff</a> — Returns the difference between two DateTime objects</li><li><a href="datetime.format.php">DateTime::format</a> — Returns date formatted according to given format</li><li><a href="datetime.getlasterrors.php">DateTime::getLastErrors</a> — Returns the warnings and errors</li><li><a href="datetime.getoffset.php">DateTime::getOffset</a> — Returns the timezone offset</li><li><a href="datetime.gettimestamp.php">DateTime::getTimestamp</a> — Gets the Unix timestamp</li><li><a href="datetime.gettimezone.php">DateTime::getTimezone</a> — Return time zone relative to given DateTime</li><li><a href="datetime.modify.php">DateTime::modify</a> — Alters the timestamp</li><li><a href="datetime.set-state.php">DateTime::__set_state</a> — The __set_state handler</li><li><a href="datetime.setdate.php">DateTime::setDate</a> — Sets the date</li><li><a href="datetime.setisodate.php">DateTime::setISODate</a> — Sets the ISO date</li><li><a href="datetime.settime.php">DateTime::setTime</a> — Sets the time</li><li><a href="datetime.settimestamp.php">DateTime::setTimestamp</a> — Sets the date and time based on an Unix timestamp</li><li><a href="datetime.settimezone.php">DateTime::setTimezone</a> — Sets the time zone for the DateTime object</li><li><a href="datetime.sub.php">DateTime::sub</a> — Subtracts an amount of days, months, years, hours, minutes and seconds from
   a DateTime object</li><li><a href="datetime.wakeup.php">DateTime::__wakeup</a> — The __wakeup handler</li></ul>
</div>
<?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites