<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<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>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<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>
<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>
<!--End of Navigation Panel-->
<H2><A NAME=
"SECTION0081040000000000000000"></A><A NAME=
"datetime-datetime"></A>
6.10.4 <tt class=
"class">datetime
</tt> Objects
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
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <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>
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:
<LI><code>MINYEAR
<=
<var>year
</var> <= MAXYEAR
</code>
<LI><code>1 <=
<var>month
</var> <=
12</code>
<LI><code>1 <=
<var>day
</var> <= number of days in the given month and year
</code>
<LI><code>0 <=
<var>hour
</var> < 24</code>
<LI><code>0 <=
<var>minute
</var> < 60</code>
<LI><code>0 <=
<var>second
</var> < 60</code>
<LI><code>0 <=
<var>microsecond
</var> < 1000000</code>
If an argument outside those ranges is given,
<tt class=
"exception">ValueError
</tt> is raised.
Other constructors, all class methods:
<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>
Return the current local datetime, with
<tt class=
"member">tzinfo
</tt> <code>None
</code>.
<code>datetime.fromtimestamp(time.time())
</code>.
See also
<tt class=
"method">now()
</tt>,
<tt class=
"method">fromtimestamp()
</tt>.
<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>
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).
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><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>
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><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>
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.
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>.
<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><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>
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><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>
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 <= ordinal
<=
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><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>
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
<dl><dt><b><tt id='l2h-
1895' xml:id='l2h-
1895'
class=
"member">min
</tt></b></dt>
The earliest representable
<tt class=
"class">datetime
</tt>,
<code>datetime(MINYEAR,
1,
1, tzinfo=None)
</code>.
<dl><dt><b><tt id='l2h-
1896' xml:id='l2h-
1896'
class=
"member">max
</tt></b></dt>
The latest representable
<tt class=
"class">datetime
</tt>,
<code>datetime(MAXYEAR,
12,
31,
23,
59,
59,
999999, tzinfo=None)
</code>.
<dl><dt><b><tt id='l2h-
1897' xml:id='l2h-
1897'
class=
"member">resolution
</tt></b></dt>
The smallest possible difference between non-equal
<tt class=
"class">datetime
</tt>
objects,
<code>timedelta(microseconds=
1)
</code>.
Instance attributes (read-only):
<dl><dt><b><tt id='l2h-
1898' xml:id='l2h-
1898'
class=
"member">year
</tt></b></dt>
Between
<tt class=
"constant">MINYEAR
</tt> and
<tt class=
"constant">MAXYEAR
</tt> inclusive.
<dl><dt><b><tt id='l2h-
1899' xml:id='l2h-
1899'
class=
"member">month
</tt></b></dt>
Between
1 and
12 inclusive.
<dl><dt><b><tt id='l2h-
1900' xml:id='l2h-
1900'
class=
"member">day
</tt></b></dt>
Between
1 and the number of days in the given month of the given
<dl><dt><b><tt id='l2h-
1901' xml:id='l2h-
1901'
class=
"member">hour
</tt></b></dt>
In
<code>range(
24)
</code>.
<dl><dt><b><tt id='l2h-
1902' xml:id='l2h-
1902'
class=
"member">minute
</tt></b></dt>
In
<code>range(
60)
</code>.
<dl><dt><b><tt id='l2h-
1903' xml:id='l2h-
1903'
class=
"member">second
</tt></b></dt>
In
<code>range(
60)
</code>.
<dl><dt><b><tt id='l2h-
1904' xml:id='l2h-
1904'
class=
"member">microsecond
</tt></b></dt>
In
<code>range(
1000000)
</code>.
<dl><dt><b><tt id='l2h-
1905' xml:id='l2h-
1905'
class=
"member">tzinfo
</tt></b></dt>
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.
<div class=
"center"><table class=
"realtable">
<th class=
"center">Operation
</th>
<th class=
"left" >Result
</th>
<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> < <var>datetime2
</var></code></td>
<td class=
"left" >Compares
<tt class=
"class">datetime
</tt> to
<tt class=
"class">datetime
</tt>.
<DT><STRONG>(
1)
</STRONG></DT>
datetime2 is a duration of timedelta removed from datetime1, moving
forward in time if
<code><var>timedelta
</var>.days
</code> > 0, or backward if
<code><var>timedelta
</var>.days
</code> < 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
<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
This isn't quite equivalent to datetime1 + (-timedelta), because
-timedelta in isolation can overflow in cases where
datetime1 - timedelta does not.
<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.
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.
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.
<DT><STRONG>(
4)
</STRONG></DT>
<var>datetime1
</var> is considered less than
<var>datetime2
</var>
when
<var>datetime1
</var> precedes
<var>datetime2
</var> in time.
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>,
<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.
<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>
Return
<tt class=
"class">date
</tt> object with same year, month and day.
<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>
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><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>
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><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>
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><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>
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.
<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
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).
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>.
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>
<div class=
"verbatim"><pre>
def astimezone(self, tz):
# 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.
<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>
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><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>
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><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>
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
<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>
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>.toordinal() - date(
<var>d
</var>.year,
1,
1).toordinal() +
1,
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><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>
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
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
<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>
Return the proleptic Gregorian ordinal of the date. The same as
<code>self.date().toordinal()
</code>.
<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>
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><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>
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><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>
Return a
3-tuple, (ISO year, ISO week number, ISO weekday). The
same as
<code>self.date().isocalendar()
</code>.
<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>
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,
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
YYYY-MM-DDTHH:MM:SS.mmmmmm+HH:MM
or, if
<tt class=
"member">microsecond
</tt> is
0
YYYY-MM-DDTHH:MM:SS+HH:MM
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,
<div class=
"verbatim"><pre>
>>> from datetime import tzinfo, timedelta, datetime
>>> class TZ(tzinfo):
... def utcoffset(self, dt): return timedelta(minutes=-
399)
>>> datetime(
2002,
12,
25, tzinfo=TZ()).isoformat(' ')
'
2002-
12-
25 00:
00:
00-
06:
39'
<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>
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><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>
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
<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>
Return a string representing the date and time, controlled by an
explicit format string. See the section on
<tt class=
"method">strftime()
</tt>
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<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>
<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>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.