MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //usr/share/doc/python-docs-2.4.3/html/lib/datetime-datetime.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="datetime-time.html" />
<link rel="prev" href="datetime-date.html" />
<link rel="parent" href="module-datetime.html" />
<link rel="next" href="datetime-time.html" />
<meta name='aesop' content='information' />
<title>6.10.4 datetime Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.10.3 date Objects"
  href="datetime-date.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="6.10 datetime  "
  href="module-datetime.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="6.10.5 time Objects"
  href="datetime-time.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="datetime-date.html">6.10.3 date Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-datetime.html">6.10 datetime  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="datetime-time.html">6.10.5 time Objects</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION0081040000000000000000"></A><A NAME="datetime-datetime"></A>
<BR>
6.10.4 <tt class="class">datetime</tt> Objects 
</H2>

<P>
A <tt class="class">datetime</tt> object is a single object containing all the
information from a <tt class="class">date</tt> object and a <tt class="class">time</tt> object.  Like a
<tt class="class">date</tt> object, <tt class="class">datetime</tt> assumes the current Gregorian
calendar extended in both directions; like a time object,
<tt class="class">datetime</tt> assumes there are exactly 3600*24 seconds in every
day.

<P>
Constructor:

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-1887' xml:id='l2h-1887' class="class">datetime</tt></b>(</nobr></td>
  <td><var>year, month, day</var><big>[</big><var>,
                            hour</var><big>[</big><var>, minute</var><big>[</big><var>,
                            second</var><big>[</big><var>, microsecond</var><big>[</big><var>,
                            tzinfo</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  The year, month and day arguments are required.  <var>tzinfo</var> may
  be <code>None</code>, or an instance of a <tt class="class">tzinfo</tt> subclass.  The
  remaining arguments may be ints or longs, in the following ranges:

<P>

<UL>
<LI><code>MINYEAR &lt;= <var>year</var> &lt;= MAXYEAR</code>
</LI>
<LI><code>1 &lt;= <var>month</var> &lt;= 12</code>
</LI>
<LI><code>1 &lt;= <var>day</var> &lt;= number of days in the given month and year</code>
</LI>
<LI><code>0 &lt;= <var>hour</var> &lt; 24</code>
</LI>
<LI><code>0 &lt;= <var>minute</var> &lt; 60</code>
</LI>
<LI><code>0 &lt;= <var>second</var> &lt; 60</code>
</LI>
<LI><code>0 &lt;= <var>microsecond</var> &lt; 1000000</code>
  
</LI>
</UL>

<P>
If an argument outside those ranges is given,
  <tt class="exception">ValueError</tt> is raised.
</dl>

<P>
Other constructors, all class methods:

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1888' xml:id='l2h-1888' class="method">today</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the current local datetime, with <tt class="member">tzinfo</tt> <code>None</code>.
  This is equivalent to
  <code>datetime.fromtimestamp(time.time())</code>.
  See also <tt class="method">now()</tt>, <tt class="method">fromtimestamp()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1889' xml:id='l2h-1889' class="method">now</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>tz</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return the current local date and time.  If optional argument
  <var>tz</var> is <code>None</code> or not specified, this is like
  <tt class="method">today()</tt>, but, if possible, supplies more precision than can
  be gotten from going through a <tt class="function">time.time()</tt> timestamp (for
  example, this may be possible on platforms supplying the C
  <tt class="cfunction">gettimeofday()</tt> function).

<P>
Else <var>tz</var> must be an instance of a class <tt class="class">tzinfo</tt> subclass,
  and the current date and time are converted to <var>tz</var>'s time
  zone.  In this case the result is equivalent to
  <code><var>tz</var>.fromutc(datetime.utcnow().replace(tzinfo=<var>tz</var>))</code>.
  See also <tt class="method">today()</tt>, <tt class="method">utcnow()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1890' xml:id='l2h-1890' class="method">utcnow</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the current UTC date and time, with <tt class="member">tzinfo</tt> <code>None</code>.
  This is like <tt class="method">now()</tt>, but returns the current UTC date and time,
  as a naive <tt class="class">datetime</tt> object.
  See also <tt class="method">now()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1891' xml:id='l2h-1891' class="method">fromtimestamp</tt></b>(</nobr></td>
  <td><var>timestamp</var><big>[</big><var>, tz</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return the local date and time corresponding to the POSIX
  timestamp, such as is returned by <tt class="function">time.time()</tt>.
  If optional argument <var>tz</var> is <code>None</code> or not specified, the
  timestamp is converted to the platform's local date and time, and
  the returned <tt class="class">datetime</tt> object is naive.

<P>
Else <var>tz</var> must be an instance of a class <tt class="class">tzinfo</tt> subclass,
  and the timestamp is converted to <var>tz</var>'s time zone.  In this case
  the result is equivalent to
  <code><var>tz</var>.fromutc(datetime.utcfromtimestamp(<var>timestamp</var>).replace(tzinfo=<var>tz</var>))</code>.

<P>
<tt class="method">fromtimestamp()</tt> may raise <tt class="exception">ValueError</tt>, if the
  timestamp is out of the range of values supported by the platform C
  <tt class="cfunction">localtime()</tt> or <tt class="cfunction">gmtime()</tt> functions.  It's common
  for this to be restricted to years in 1970 through 2038.
  Note that on non-POSIX systems that include leap seconds in their
  notion of a timestamp, leap seconds are ignored by
  <tt class="method">fromtimestamp()</tt>, and then it's possible to have two timestamps
  differing by a second that yield identical <tt class="class">datetime</tt> objects.
  See also <tt class="method">utcfromtimestamp()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1892' xml:id='l2h-1892' class="method">utcfromtimestamp</tt></b>(</nobr></td>
  <td><var>timestamp</var>)</td></tr></table></dt>
<dd>
  Return the UTC <tt class="class">datetime</tt> corresponding to the POSIX
  timestamp, with <tt class="member">tzinfo</tt> <code>None</code>.
  This may raise <tt class="exception">ValueError</tt>, if the
  timestamp is out of the range of values supported by the platform
  C <tt class="cfunction">gmtime()</tt> function.  It's common for this to be
  restricted to years in 1970 through 2038.
  See also <tt class="method">fromtimestamp()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1893' xml:id='l2h-1893' class="method">fromordinal</tt></b>(</nobr></td>
  <td><var>ordinal</var>)</td></tr></table></dt>
<dd>
  Return the <tt class="class">datetime</tt> corresponding to the proleptic
  Gregorian ordinal, where January 1 of year 1 has ordinal 1.
  <tt class="exception">ValueError</tt> is raised unless <code>1 &lt;= ordinal &lt;=
  datetime.max.toordinal()</code>.  The hour, minute, second and
  microsecond of the result are all 0,
  and <tt class="member">tzinfo</tt> is <code>None</code>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1894' xml:id='l2h-1894' class="method">combine</tt></b>(</nobr></td>
  <td><var>date, time</var>)</td></tr></table></dt>
<dd>
  Return a new <tt class="class">datetime</tt> object whose date members are
  equal to the given <tt class="class">date</tt> object's, and whose time
  and <tt class="member">tzinfo</tt> members are equal to the given <tt class="class">time</tt> object's.
  For any <tt class="class">datetime</tt> object <var>d</var>, <code><var>d</var> ==
  datetime.combine(<var>d</var>.date(), <var>d</var>.timetz())</code>.  If date is a
  <tt class="class">datetime</tt> object, its time and <tt class="member">tzinfo</tt> members are
  ignored.
  </dl>

<P>
Class attributes:

<P>
<dl><dt><b><tt id='l2h-1895' xml:id='l2h-1895' class="member">min</tt></b></dt>
<dd>
  The earliest representable <tt class="class">datetime</tt>,
  <code>datetime(MINYEAR, 1, 1, tzinfo=None)</code>.
</dl>

<P>
<dl><dt><b><tt id='l2h-1896' xml:id='l2h-1896' class="member">max</tt></b></dt>
<dd>
  The latest representable <tt class="class">datetime</tt>,
  <code>datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999, tzinfo=None)</code>.
</dl>

<P>
<dl><dt><b><tt id='l2h-1897' xml:id='l2h-1897' class="member">resolution</tt></b></dt>
<dd>
  The smallest possible difference between non-equal <tt class="class">datetime</tt>
  objects, <code>timedelta(microseconds=1)</code>.
</dl>

<P>
Instance attributes (read-only):

<P>
<dl><dt><b><tt id='l2h-1898' xml:id='l2h-1898' class="member">year</tt></b></dt>
<dd>
  Between <tt class="constant">MINYEAR</tt> and <tt class="constant">MAXYEAR</tt> inclusive.
</dl>

<P>
<dl><dt><b><tt id='l2h-1899' xml:id='l2h-1899' class="member">month</tt></b></dt>
<dd>
  Between 1 and 12 inclusive.
</dl>

<P>
<dl><dt><b><tt id='l2h-1900' xml:id='l2h-1900' class="member">day</tt></b></dt>
<dd>
  Between 1 and the number of days in the given month of the given
  year.
</dl>

<P>
<dl><dt><b><tt id='l2h-1901' xml:id='l2h-1901' class="member">hour</tt></b></dt>
<dd>
  In <code>range(24)</code>.
</dl>

<P>
<dl><dt><b><tt id='l2h-1902' xml:id='l2h-1902' class="member">minute</tt></b></dt>
<dd>
  In <code>range(60)</code>.
</dl>

<P>
<dl><dt><b><tt id='l2h-1903' xml:id='l2h-1903' class="member">second</tt></b></dt>
<dd>
  In <code>range(60)</code>.
</dl>

<P>
<dl><dt><b><tt id='l2h-1904' xml:id='l2h-1904' class="member">microsecond</tt></b></dt>
<dd>
  In <code>range(1000000)</code>.
</dl>

<P>
<dl><dt><b><tt id='l2h-1905' xml:id='l2h-1905' class="member">tzinfo</tt></b></dt>
<dd>
  The object passed as the <var>tzinfo</var> argument to the
  <tt class="class">datetime</tt> constructor, or <code>None</code> if none was passed.
</dl>

<P>
Supported operations:

<P>
<div class="center"><table class="realtable">
  <thead>
    <tr>
      <th class="center">Operation</th>
      <th class="left"  >Result</th>
      </tr>
    </thead>
  <tbody>
    <tr><td class="center" valign="baseline"><code><var>datetime2</var> = <var>datetime1</var> + <var>timedelta</var></code></td>
        <td class="left"  >(1)</td></tr><P>

    <tr><td class="center" valign="baseline"><code><var>datetime2</var> = <var>datetime1</var> - <var>timedelta</var></code></td>
        <td class="left"  >(2)</td></tr><P>

    <tr><td class="center" valign="baseline"><code><var>timedelta</var> = <var>datetime1</var> - <var>datetime2</var></code></td>
        <td class="left"  >(3)</td></tr><P>

    <tr><td class="center" valign="baseline"><code><var>datetime1</var> &lt; <var>datetime2</var></code></td>
        <td class="left"  >Compares <tt class="class">datetime</tt> to <tt class="class">datetime</tt>.
    (4)</td></tr><P>

    </tbody>
</table></div>

<P>
<DL>
<DT><STRONG>(1)</STRONG></DT>
<DD><P>
datetime2 is a duration of timedelta removed from datetime1, moving
    forward in time if <code><var>timedelta</var>.days</code> &gt; 0, or backward if
    <code><var>timedelta</var>.days</code> &lt; 0.  The result has the same <tt class="member">tzinfo</tt> member
    as the input datetime, and datetime2 - datetime1 == timedelta after.
    <tt class="exception">OverflowError</tt> is raised if datetime2.year would be
    smaller than <tt class="constant">MINYEAR</tt> or larger than <tt class="constant">MAXYEAR</tt>.
    Note that no time zone adjustments are done even if the input is an
    aware object.

<P>
</DD>
<DT><STRONG>(2)</STRONG></DT>
<DD>Computes the datetime2 such that datetime2 + timedelta == datetime1.
    As for addition, the result has the same <tt class="member">tzinfo</tt> member
    as the input datetime, and no time zone adjustments are done even
    if the input is aware.
    This isn't quite equivalent to datetime1 + (-timedelta), because
    -timedelta in isolation can overflow in cases where
    datetime1 - timedelta does not.

<P>
</DD>
<DT><STRONG>(3)</STRONG></DT>
<DD>Subtraction of a <tt class="class">datetime</tt> from a
    <tt class="class">datetime</tt> is defined only if both
    operands are naive, or if both are aware.  If one is aware and the
    other is naive, <tt class="exception">TypeError</tt> is raised.

<P>
If both are naive, or both are aware and have the same <tt class="member">tzinfo</tt>
    member, the <tt class="member">tzinfo</tt> members are ignored, and the result is
    a <tt class="class">timedelta</tt> object <var>t</var> such that
    <code><var>datetime2</var> + <var>t</var> == <var>datetime1</var></code>.  No time zone
    adjustments are done in this case.

<P>
If both are aware and have different <tt class="member">tzinfo</tt> members,
    <code>a-b</code> acts as if <var>a</var> and <var>b</var> were first converted to
    naive UTC datetimes first.  The result is
    <code>(<var>a</var>.replace(tzinfo=None) - <var>a</var>.utcoffset()) -
          (<var>b</var>.replace(tzinfo=None) - <var>b</var>.utcoffset())</code>
    except that the implementation never overflows.

<P>
</DD>
<DT><STRONG>(4)</STRONG></DT>
<DD><P>
<var>datetime1</var> is considered less than <var>datetime2</var>
when <var>datetime1</var> precedes <var>datetime2</var> in time.

<P>
If one comparand is naive and
the other is aware, <tt class="exception">TypeError</tt> is raised.  If both
    comparands are aware, and have the same <tt class="member">tzinfo</tt> member,
    the common <tt class="member">tzinfo</tt> member is ignored and the base datetimes
    are compared.  If both comparands are aware and have different
    <tt class="member">tzinfo</tt> members, the comparands are first adjusted by
    subtracting their UTC offsets (obtained from <code>self.utcoffset()</code>).
    <span class="note"><b class="label">Note:</b>
In order to stop comparison from falling back to the default
          scheme of comparing object addresses, datetime comparison
          normally raises <tt class="exception">TypeError</tt> if the other comparand
          isn't also a <tt class="class">datetime</tt> object.  However,
          <code>NotImplemented</code> is returned instead if the other comparand
          has a <tt class="method">timetuple</tt> attribute.  This hook gives other
          kinds of date objects a chance at implementing mixed-type
          comparison.  If not, when a <tt class="class">datetime</tt> object is
          compared to an object of a different type, <tt class="exception">TypeError</tt>
          is raised unless the comparison is <code>==</code> or <code>!=</code>.  The
          latter cases return <tt class="constant">False</tt> or <tt class="constant">True</tt>,
          respectively.</span>

<P>
</DD>
</DL>

<P>
<tt class="class">datetime</tt> objects can be used as dictionary keys. In Boolean
contexts, all <tt class="class">datetime</tt> objects are considered to be true.

<P>
Instance methods:

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1906' xml:id='l2h-1906' class="method">date</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return <tt class="class">date</tt> object with same year, month and day.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1907' xml:id='l2h-1907' class="method">time</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return <tt class="class">time</tt> object with same hour, minute, second and microsecond.
  <tt class="member">tzinfo</tt> is <code>None</code>.  See also method <tt class="method">timetz()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1908' xml:id='l2h-1908' class="method">timetz</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return <tt class="class">time</tt> object with same hour, minute, second, microsecond,
  and tzinfo members.  See also method <tt class="method">time()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1909' xml:id='l2h-1909' class="method">replace</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>year</var><big>[</big><var>, month</var><big>[</big><var>,
                            day</var><big>[</big><var>, hour</var><big>[</big><var>, minute</var><big>[</big><var>,
                            second</var><big>[</big><var>, microsecond</var><big>[</big><var>,
                            tzinfo</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a datetime with the same members, except for those members given
  new values by whichever keyword arguments are specified.  Note that
  <code>tzinfo=None</code> can be specified to create a naive datetime from
  an aware datetime with no conversion of date and time members.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1910' xml:id='l2h-1910' class="method">astimezone</tt></b>(</nobr></td>
  <td><var>tz</var>)</td></tr></table></dt>
<dd>
  Return a <tt class="class">datetime</tt> object with new <tt class="member">tzinfo</tt> member
  <var>tz</var>, adjusting the date and time members so the result is the
  same UTC time as <var>self</var>, but in <var>tz</var>'s local time.

<P>
<var>tz</var> must be an instance of a <tt class="class">tzinfo</tt> subclass, and its
  <tt class="method">utcoffset()</tt> and <tt class="method">dst()</tt> methods must not return
  <code>None</code>.  <var>self</var> must be aware (<code><var>self</var>.tzinfo</code> must
  not be <code>None</code>, and <code><var>self</var>.utcoffset()</code> must not return
  <code>None</code>).

<P>
If <code><var>self</var>.tzinfo</code> is <var>tz</var>,
  <code><var>self</var>.astimezone(<var>tz</var>)</code> is equal to <var>self</var>:  no
  adjustment of date or time members is performed.
  Else the result is local time in time zone <var>tz</var>, representing the
  same UTC time as <var>self</var>:  after <code><var>astz</var> =
  <var>dt</var>.astimezone(<var>tz</var>)</code>,
  <code><var>astz</var> - <var>astz</var>.utcoffset()</code> will usually have the same
  date and time members as <code><var>dt</var> - <var>dt</var>.utcoffset()</code>.
  The discussion of class <tt class="class">tzinfo</tt> explains the cases at Daylight
  Saving Time transition boundaries where this cannot be achieved (an issue
  only if <var>tz</var> models both standard and daylight time).

<P>
If you merely want to attach a time zone object <var>tz</var> to a
  datetime <var>dt</var> without adjustment of date and time members,
  use <code><var>dt</var>.replace(tzinfo=<var>tz</var>)</code>.  If
  you merely want to remove the time zone object from an aware datetime
  <var>dt</var> without conversion of date and time members, use
  <code><var>dt</var>.replace(tzinfo=None)</code>.

<P>
Note that the default <tt class="method">tzinfo.fromutc()</tt> method can be overridden
  in a <tt class="class">tzinfo</tt> subclass to affect the result returned by
  <tt class="method">astimezone()</tt>.  Ignoring error cases, <tt class="method">astimezone()</tt>
  acts like:

<P>
<div class="verbatim"><pre>
  def astimezone(self, tz):
      if self.tzinfo is tz:
          return self
      # Convert self to UTC, and attach the new time zone object.
      utc = (self - self.utcoffset()).replace(tzinfo=tz)
      # Convert from UTC to tz's local time.
      return tz.fromutc(utc)
</pre></div>
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1911' xml:id='l2h-1911' class="method">utcoffset</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else
  returns <code><var>self</var>.tzinfo.utcoffset(<var>self</var>)</code>, and
  raises an exception if the latter doesn't return <code>None</code>, or
  a <tt class="class">timedelta</tt> object representing a whole number of minutes
  with magnitude less than one day.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1912' xml:id='l2h-1912' class="method">dst</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else
  returns <code><var>self</var>.tzinfo.dst(<var>self</var>)</code>, and
  raises an exception if the latter doesn't return <code>None</code>, or
  a <tt class="class">timedelta</tt> object representing a whole number of minutes
  with magnitude less than one day.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1913' xml:id='l2h-1913' class="method">tzname</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else
  returns <code><var>self</var>.tzinfo.tzname(<var>self</var>)</code>,
  raises an exception if the latter doesn't return <code>None</code> or
  a string object,
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1914' xml:id='l2h-1914' class="method">timetuple</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return a <tt class="class">time.struct_time</tt> such as returned by
  <tt class="function">time.localtime()</tt>.
  <code><var>d</var>.timetuple()</code> is equivalent to
  <code>time.struct_time((<var>d</var>.year, <var>d</var>.month, <var>d</var>.day,
         <var>d</var>.hour, <var>d</var>.minute, <var>d</var>.second,
         <var>d</var>.weekday(),
         <var>d</var>.toordinal() - date(<var>d</var>.year, 1, 1).toordinal() + 1,
         dst))</code>
  The <tt class="member">tm_isdst</tt> flag of the result is set according to
  the <tt class="method">dst()</tt> method:  <tt class="member">tzinfo</tt> is <code>None</code> or
  <tt class="method">dst()</tt> returns <code>None</code>,
  <tt class="member">tm_isdst</tt> is set to  <code>-1</code>; else if <tt class="method">dst()</tt> returns
  a non-zero value, <tt class="member">tm_isdst</tt> is set to <code>1</code>;
  else <code>tm_isdst</code> is set to <code>0</code>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1915' xml:id='l2h-1915' class="method">utctimetuple</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  If <tt class="class">datetime</tt> instance <var>d</var> is naive, this is the same as
  <code><var>d</var>.timetuple()</code> except that <tt class="member">tm_isdst</tt> is forced to 0
  regardless of what <code>d.dst()</code> returns.  DST is never in effect
  for a UTC time.

<P>
If <var>d</var> is aware, <var>d</var> is normalized to UTC time, by subtracting
  <code><var>d</var>.utcoffset()</code>, and a <tt class="class">time.struct_time</tt> for the
  normalized time is returned.  <tt class="member">tm_isdst</tt> is forced to 0.
  Note that the result's <tt class="member">tm_year</tt> member may be
  <tt class="constant">MINYEAR</tt>-1 or <tt class="constant">MAXYEAR</tt>+1, if <var>d</var>.year was
  <code>MINYEAR</code> or <code>MAXYEAR</code> and UTC adjustment spills over a
  year boundary.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1916' xml:id='l2h-1916' class="method">toordinal</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the proleptic Gregorian ordinal of the date.  The same as
  <code>self.date().toordinal()</code>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1917' xml:id='l2h-1917' class="method">weekday</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the day of the week as an integer, where Monday is 0 and
  Sunday is 6.  The same as <code>self.date().weekday()</code>.
  See also <tt class="method">isoweekday()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1918' xml:id='l2h-1918' class="method">isoweekday</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the day of the week as an integer, where Monday is 1 and
  Sunday is 7.  The same as <code>self.date().isoweekday()</code>.
  See also <tt class="method">weekday()</tt>, <tt class="method">isocalendar()</tt>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1919' xml:id='l2h-1919' class="method">isocalendar</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return a 3-tuple, (ISO year, ISO week number, ISO weekday).  The
  same as <code>self.date().isocalendar()</code>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1920' xml:id='l2h-1920' class="method">isoformat</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>sep</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a string representing the date and time in ISO 8601 format,
      YYYY-MM-DDTHH:MM:SS.mmmmmm
  or, if <tt class="member">microsecond</tt> is 0,
      YYYY-MM-DDTHH:MM:SS

<P>
If <tt class="method">utcoffset()</tt> does not return <code>None</code>, a 6-character
  string is appended, giving the UTC offset in (signed) hours and
  minutes:
      YYYY-MM-DDTHH:MM:SS.mmmmmm+HH:MM
  or, if <tt class="member">microsecond</tt> is 0
      YYYY-MM-DDTHH:MM:SS+HH:MM

<P>
The optional argument <var>sep</var> (default <code>'T'</code>) is a
  one-character separator, placed between the date and time portions
  of the result.  For example,

<P>
<div class="verbatim"><pre>
&gt;&gt;&gt; from datetime import tzinfo, timedelta, datetime
&gt;&gt;&gt; class TZ(tzinfo):
...     def utcoffset(self, dt): return timedelta(minutes=-399)
...
&gt;&gt;&gt; datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
'2002-12-25 00:00:00-06:39'
</pre></div>
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1921' xml:id='l2h-1921' class="method">__str__</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  For a <tt class="class">datetime</tt> instance <var>d</var>, <code>str(<var>d</var>)</code> is
  equivalent to <code><var>d</var>.isoformat(' ')</code>.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1922' xml:id='l2h-1922' class="method">ctime</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return a string representing the date and time, for example
  <code>datetime(2002, 12, 4, 20, 30, 40).ctime() ==
   'Wed Dec  4 20:30:40 2002'</code>.
  <code>d.ctime()</code> is equivalent to
  <code>time.ctime(time.mktime(d.timetuple()))</code> on platforms where
  the native C <tt class="cfunction">ctime()</tt> function (which
  <tt class="function">time.ctime()</tt> invokes, but which
  <tt class="method">datetime.ctime()</tt> does not invoke) conforms to the C
  standard.
</dl>

<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1923' xml:id='l2h-1923' class="method">strftime</tt></b>(</nobr></td>
  <td><var>format</var>)</td></tr></table></dt>
<dd>
  Return a string representing the date and time, controlled by an
  explicit format string.  See the section on <tt class="method">strftime()</tt>
  behavior.
</dl>

<P>

<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.10.3 date Objects"
  href="datetime-date.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="6.10 datetime  "
  href="module-datetime.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="6.10.5 time Objects"
  href="datetime-time.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="datetime-date.html">6.10.3 date Objects</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-datetime.html">6.10 datetime  </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="datetime-time.html">6.10.5 time Objects</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.3, documentation updated on 29 March 2006.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>