<!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-tzinfo.html" />
<link rel=
"prev" href=
"datetime-datetime.html" />
<link rel=
"parent" href=
"module-datetime.html" />
<link rel=
"next" href=
"datetime-tzinfo.html" />
<meta name='aesop' content='information'
/>
<title>6.10.5 time 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.4 datetime Objects"
href=
"datetime-datetime.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.6 tzinfo Objects"
href=
"datetime-tzinfo.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-datetime.html">6.10.4 datetime 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-tzinfo.html">6.10.6 tzinfo Objects
</A>
<!--End of Navigation Panel-->
<H2><A NAME=
"SECTION0081050000000000000000"></A><A NAME=
"datetime-time"></A>
6.10.5 <tt class=
"class">time
</tt> Objects
A time object represents a (local) time of day, independent of any
particular day, and subject to adjustment via a
<tt class=
"class">tzinfo
</tt> object.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
1924' xml:id='l2h-
1924'
class=
"class">time
</tt></b>(
</nobr></td>
<td><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>)
</td></tr></table></dt>
All arguments are optional.
<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>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. All default to
<code>0</code> except
<var>tzinfo
</var>, which defaults to
<tt class=
"constant">None
</tt>.
<dl><dt><b><tt id='l2h-
1925' xml:id='l2h-
1925'
class=
"member">min
</tt></b></dt>
The earliest representable
<tt class=
"class">time
</tt>,
<code>time(
0,
0,
0,
0)
</code>.
<dl><dt><b><tt id='l2h-
1926' xml:id='l2h-
1926'
class=
"member">max
</tt></b></dt>
The latest representable
<tt class=
"class">time
</tt>,
<code>time(
23,
59,
59,
999999)
</code>.
<dl><dt><b><tt id='l2h-
1927' xml:id='l2h-
1927'
class=
"member">resolution
</tt></b></dt>
The smallest possible difference between non-equal
<tt class=
"class">time
</tt>
objects,
<code>timedelta(microseconds=
1)
</code>, although note that
arithmetic on
<tt class=
"class">time
</tt> objects is not supported.
Instance attributes (read-only):
<dl><dt><b><tt id='l2h-
1928' xml:id='l2h-
1928'
class=
"member">hour
</tt></b></dt>
In
<code>range(
24)
</code>.
<dl><dt><b><tt id='l2h-
1929' xml:id='l2h-
1929'
class=
"member">minute
</tt></b></dt>
In
<code>range(
60)
</code>.
<dl><dt><b><tt id='l2h-
1930' xml:id='l2h-
1930'
class=
"member">second
</tt></b></dt>
In
<code>range(
60)
</code>.
<dl><dt><b><tt id='l2h-
1931' xml:id='l2h-
1931'
class=
"member">microsecond
</tt></b></dt>
In
<code>range(
1000000)
</code>.
<dl><dt><b><tt id='l2h-
1932' xml:id='l2h-
1932'
class=
"member">tzinfo
</tt></b></dt>
The object passed as the tzinfo argument to the
<tt class=
"class">time
</tt>
constructor, or
<code>None
</code> if none was passed.
<LI>comparison of
<tt class=
"class">time
</tt> to
<tt class=
"class">time
</tt>,
where
<var>a
</var> is considered less than
<var>b
</var> when
<var>a
</var> precedes
<var>b
</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 times 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>).
In order to stop mixed-type comparisons from falling back to the
default comparison by object address, when a
<tt class=
"class">time
</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.
<LI>hash, use as dict key
<LI>in Boolean contexts, a
<tt class=
"class">time
</tt> object is considered to be
true if and only if, after converting it to minutes and
subtracting
<tt class=
"method">utcoffset()
</tt> (or
<code>0</code> if that's
<code>None
</code>), the result is non-zero.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1933' xml:id='l2h-
1933'
class=
"method">replace
</tt></b>(
</nobr></td>
<td><var></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>
Return a
<tt class=
"class">time
</tt> with the same value, 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
<tt class=
"class">time
</tt> from
an aware
<tt class=
"class">time
</tt>, without conversion of the time members.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1934' xml:id='l2h-
1934'
class=
"method">isoformat
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Return a string representing the time in ISO
8601 format,
or, if self.microsecond 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
or, if self.microsecond is
0,
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1935' xml:id='l2h-
1935'
class=
"method">__str__
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
For a time
<var>t
</var>,
<code>str(
<var>t
</var>)
</code> is equivalent to
<code><var>t
</var>.isoformat()
</code>.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1936' xml:id='l2h-
1936'
class=
"method">strftime
</tt></b>(
</nobr></td>
<td><var>format
</var>)
</td></tr></table></dt>
Return a string representing the time, controlled by an explicit
format string. See the section on
<tt class=
"method">strftime()
</tt> behavior.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><tt id='l2h-
1937' xml:id='l2h-
1937'
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(None)
</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-
1938' xml:id='l2h-
1938'
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(None)
</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-
1939' xml:id='l2h-
1939'
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(None)
</code>, or
raises an exception if the latter doesn't return
<code>None
</code> or
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.10.4 datetime Objects"
href=
"datetime-datetime.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.6 tzinfo Objects"
href=
"datetime-tzinfo.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-datetime.html">6.10.4 datetime 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-tzinfo.html">6.10.6 tzinfo 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.