| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="datetime-tzinfo.html" /> |
| 13 | <link rel="prev" href="datetime-datetime.html" /> |
| 14 | <link rel="parent" href="module-datetime.html" /> |
| 15 | <link rel="next" href="datetime-tzinfo.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>6.10.5 time Objects </title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="6.10.4 datetime Objects" |
| 25 | href="datetime-datetime.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="6.10 datetime " |
| 28 | href="module-datetime.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="6.10.6 tzinfo Objects" |
| 31 | href="datetime-tzinfo.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="datetime-datetime.html">6.10.4 datetime Objects</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="module-datetime.html">6.10 datetime </A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="datetime-tzinfo.html">6.10.6 tzinfo Objects</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION0081050000000000000000"></A><A NAME="datetime-time"></A> |
| 56 | <BR> |
| 57 | 6.10.5 <tt class="class">time</tt> Objects |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | A time object represents a (local) time of day, independent of any |
| 62 | particular day, and subject to adjustment via a <tt class="class">tzinfo</tt> object. |
| 63 | |
| 64 | <P> |
| 65 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 66 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-1924' xml:id='l2h-1924' class="class">time</tt></b>(</nobr></td> |
| 67 | <td><var>hour</var><big>[</big><var>, minute</var><big>[</big><var>, second</var><big>[</big><var>, |
| 68 | 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> |
| 69 | <dd> |
| 70 | All arguments are optional. <var>tzinfo</var> may be <code>None</code>, or |
| 71 | an instance of a <tt class="class">tzinfo</tt> subclass. The remaining arguments |
| 72 | may be ints or longs, in the following ranges: |
| 73 | |
| 74 | <P> |
| 75 | |
| 76 | <UL> |
| 77 | <LI><code>0 <= <var>hour</var> < 24</code> |
| 78 | </LI> |
| 79 | <LI><code>0 <= <var>minute</var> < 60</code> |
| 80 | </LI> |
| 81 | <LI><code>0 <= <var>second</var> < 60</code> |
| 82 | </LI> |
| 83 | <LI><code>0 <= <var>microsecond</var> < 1000000</code>. |
| 84 | |
| 85 | </LI> |
| 86 | </UL> |
| 87 | |
| 88 | <P> |
| 89 | If an argument outside those ranges is given, |
| 90 | <tt class="exception">ValueError</tt> is raised. All default to <code>0</code> except |
| 91 | <var>tzinfo</var>, which defaults to <tt class="constant">None</tt>. |
| 92 | </dl> |
| 93 | |
| 94 | <P> |
| 95 | Class attributes: |
| 96 | |
| 97 | <P> |
| 98 | <dl><dt><b><tt id='l2h-1925' xml:id='l2h-1925' class="member">min</tt></b></dt> |
| 99 | <dd> |
| 100 | The earliest representable <tt class="class">time</tt>, <code>time(0, 0, 0, 0)</code>. |
| 101 | </dl> |
| 102 | |
| 103 | <P> |
| 104 | <dl><dt><b><tt id='l2h-1926' xml:id='l2h-1926' class="member">max</tt></b></dt> |
| 105 | <dd> |
| 106 | The latest representable <tt class="class">time</tt>, <code>time(23, 59, 59, 999999)</code>. |
| 107 | </dl> |
| 108 | |
| 109 | <P> |
| 110 | <dl><dt><b><tt id='l2h-1927' xml:id='l2h-1927' class="member">resolution</tt></b></dt> |
| 111 | <dd> |
| 112 | The smallest possible difference between non-equal <tt class="class">time</tt> |
| 113 | objects, <code>timedelta(microseconds=1)</code>, although note that |
| 114 | arithmetic on <tt class="class">time</tt> objects is not supported. |
| 115 | </dl> |
| 116 | |
| 117 | <P> |
| 118 | Instance attributes (read-only): |
| 119 | |
| 120 | <P> |
| 121 | <dl><dt><b><tt id='l2h-1928' xml:id='l2h-1928' class="member">hour</tt></b></dt> |
| 122 | <dd> |
| 123 | In <code>range(24)</code>. |
| 124 | </dl> |
| 125 | |
| 126 | <P> |
| 127 | <dl><dt><b><tt id='l2h-1929' xml:id='l2h-1929' class="member">minute</tt></b></dt> |
| 128 | <dd> |
| 129 | In <code>range(60)</code>. |
| 130 | </dl> |
| 131 | |
| 132 | <P> |
| 133 | <dl><dt><b><tt id='l2h-1930' xml:id='l2h-1930' class="member">second</tt></b></dt> |
| 134 | <dd> |
| 135 | In <code>range(60)</code>. |
| 136 | </dl> |
| 137 | |
| 138 | <P> |
| 139 | <dl><dt><b><tt id='l2h-1931' xml:id='l2h-1931' class="member">microsecond</tt></b></dt> |
| 140 | <dd> |
| 141 | In <code>range(1000000)</code>. |
| 142 | </dl> |
| 143 | |
| 144 | <P> |
| 145 | <dl><dt><b><tt id='l2h-1932' xml:id='l2h-1932' class="member">tzinfo</tt></b></dt> |
| 146 | <dd> |
| 147 | The object passed as the tzinfo argument to the <tt class="class">time</tt> |
| 148 | constructor, or <code>None</code> if none was passed. |
| 149 | </dl> |
| 150 | |
| 151 | <P> |
| 152 | Supported operations: |
| 153 | |
| 154 | <P> |
| 155 | |
| 156 | <UL> |
| 157 | <LI>comparison of <tt class="class">time</tt> to <tt class="class">time</tt>, |
| 158 | where <var>a</var> is considered less than <var>b</var> when <var>a</var> precedes |
| 159 | <var>b</var> in time. If one comparand is naive and the other is aware, |
| 160 | <tt class="exception">TypeError</tt> is raised. If both comparands are aware, and |
| 161 | have the same <tt class="member">tzinfo</tt> member, the common <tt class="member">tzinfo</tt> |
| 162 | member is ignored and the base times are compared. If both |
| 163 | comparands are aware and have different <tt class="member">tzinfo</tt> members, |
| 164 | the comparands are first adjusted by subtracting their UTC offsets |
| 165 | (obtained from <code>self.utcoffset()</code>). |
| 166 | In order to stop mixed-type comparisons from falling back to the |
| 167 | default comparison by object address, when a <tt class="class">time</tt> object is |
| 168 | compared to an object of a different type, <tt class="exception">TypeError</tt> is |
| 169 | raised unless the comparison is <code>==</code> or <code>!=</code>. The latter |
| 170 | cases return <tt class="constant">False</tt> or <tt class="constant">True</tt>, respectively. |
| 171 | |
| 172 | <P> |
| 173 | </LI> |
| 174 | <LI>hash, use as dict key |
| 175 | |
| 176 | <P> |
| 177 | </LI> |
| 178 | <LI>efficient pickling |
| 179 | |
| 180 | <P> |
| 181 | </LI> |
| 182 | <LI>in Boolean contexts, a <tt class="class">time</tt> object is considered to be |
| 183 | true if and only if, after converting it to minutes and |
| 184 | subtracting <tt class="method">utcoffset()</tt> (or <code>0</code> if that's |
| 185 | <code>None</code>), the result is non-zero. |
| 186 | </LI> |
| 187 | </UL> |
| 188 | |
| 189 | <P> |
| 190 | Instance methods: |
| 191 | |
| 192 | <P> |
| 193 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 194 | <td><nobr><b><tt id='l2h-1933' xml:id='l2h-1933' class="method">replace</tt></b>(</nobr></td> |
| 195 | <td><var></var><big>[</big><var>hour</var><big>[</big><var>, minute</var><big>[</big><var>, |
| 196 | second</var><big>[</big><var>, microsecond</var><big>[</big><var>, |
| 197 | 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> |
| 198 | <dd> |
| 199 | Return a <tt class="class">time</tt> with the same value, except for those members given |
| 200 | new values by whichever keyword arguments are specified. Note that |
| 201 | <code>tzinfo=None</code> can be specified to create a naive <tt class="class">time</tt> from |
| 202 | an aware <tt class="class">time</tt>, without conversion of the time members. |
| 203 | </dl> |
| 204 | |
| 205 | <P> |
| 206 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 207 | <td><nobr><b><tt id='l2h-1934' xml:id='l2h-1934' class="method">isoformat</tt></b>(</nobr></td> |
| 208 | <td><var></var>)</td></tr></table></dt> |
| 209 | <dd> |
| 210 | Return a string representing the time in ISO 8601 format, |
| 211 | HH:MM:SS.mmmmmm |
| 212 | or, if self.microsecond is 0, |
| 213 | HH:MM:SS |
| 214 | If <tt class="method">utcoffset()</tt> does not return <code>None</code>, a 6-character |
| 215 | string is appended, giving the UTC offset in (signed) hours and |
| 216 | minutes: |
| 217 | HH:MM:SS.mmmmmm+HH:MM |
| 218 | or, if self.microsecond is 0, |
| 219 | HH:MM:SS+HH:MM |
| 220 | </dl> |
| 221 | |
| 222 | <P> |
| 223 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 224 | <td><nobr><b><tt id='l2h-1935' xml:id='l2h-1935' class="method">__str__</tt></b>(</nobr></td> |
| 225 | <td><var></var>)</td></tr></table></dt> |
| 226 | <dd> |
| 227 | For a time <var>t</var>, <code>str(<var>t</var>)</code> is equivalent to |
| 228 | <code><var>t</var>.isoformat()</code>. |
| 229 | </dl> |
| 230 | |
| 231 | <P> |
| 232 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 233 | <td><nobr><b><tt id='l2h-1936' xml:id='l2h-1936' class="method">strftime</tt></b>(</nobr></td> |
| 234 | <td><var>format</var>)</td></tr></table></dt> |
| 235 | <dd> |
| 236 | Return a string representing the time, controlled by an explicit |
| 237 | format string. See the section on <tt class="method">strftime()</tt> behavior. |
| 238 | </dl> |
| 239 | |
| 240 | <P> |
| 241 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 242 | <td><nobr><b><tt id='l2h-1937' xml:id='l2h-1937' class="method">utcoffset</tt></b>(</nobr></td> |
| 243 | <td><var></var>)</td></tr></table></dt> |
| 244 | <dd> |
| 245 | If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else |
| 246 | returns <code><var>self</var>.tzinfo.utcoffset(None)</code>, and |
| 247 | raises an exception if the latter doesn't return <code>None</code> or |
| 248 | a <tt class="class">timedelta</tt> object representing a whole number of minutes |
| 249 | with magnitude less than one day. |
| 250 | </dl> |
| 251 | |
| 252 | <P> |
| 253 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 254 | <td><nobr><b><tt id='l2h-1938' xml:id='l2h-1938' class="method">dst</tt></b>(</nobr></td> |
| 255 | <td><var></var>)</td></tr></table></dt> |
| 256 | <dd> |
| 257 | If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else |
| 258 | returns <code><var>self</var>.tzinfo.dst(None)</code>, and |
| 259 | raises an exception if the latter doesn't return <code>None</code>, or |
| 260 | a <tt class="class">timedelta</tt> object representing a whole number of minutes |
| 261 | with magnitude less than one day. |
| 262 | </dl> |
| 263 | |
| 264 | <P> |
| 265 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 266 | <td><nobr><b><tt id='l2h-1939' xml:id='l2h-1939' class="method">tzname</tt></b>(</nobr></td> |
| 267 | <td><var></var>)</td></tr></table></dt> |
| 268 | <dd> |
| 269 | If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else |
| 270 | returns <code><var>self</var>.tzinfo.tzname(None)</code>, or |
| 271 | raises an exception if the latter doesn't return <code>None</code> or |
| 272 | a string object. |
| 273 | </dl> |
| 274 | |
| 275 | <P> |
| 276 | |
| 277 | <DIV CLASS="navigation"> |
| 278 | <div class='online-navigation'> |
| 279 | <p></p><hr /> |
| 280 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 281 | <tr> |
| 282 | <td class='online-navigation'><a rel="prev" title="6.10.4 datetime Objects" |
| 283 | href="datetime-datetime.html"><img src='../icons/previous.png' |
| 284 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 285 | <td class='online-navigation'><a rel="parent" title="6.10 datetime " |
| 286 | href="module-datetime.html"><img src='../icons/up.png' |
| 287 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 288 | <td class='online-navigation'><a rel="next" title="6.10.6 tzinfo Objects" |
| 289 | href="datetime-tzinfo.html"><img src='../icons/next.png' |
| 290 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 291 | <td align="center" width="100%">Python Library Reference</td> |
| 292 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 293 | href="contents.html"><img src='../icons/contents.png' |
| 294 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 295 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 296 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 297 | <td class='online-navigation'><a rel="index" title="Index" |
| 298 | href="genindex.html"><img src='../icons/index.png' |
| 299 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 300 | </tr></table> |
| 301 | <div class='online-navigation'> |
| 302 | <b class="navlabel">Previous:</b> |
| 303 | <a class="sectref" rel="prev" href="datetime-datetime.html">6.10.4 datetime Objects</A> |
| 304 | <b class="navlabel">Up:</b> |
| 305 | <a class="sectref" rel="parent" href="module-datetime.html">6.10 datetime </A> |
| 306 | <b class="navlabel">Next:</b> |
| 307 | <a class="sectref" rel="next" href="datetime-tzinfo.html">6.10.6 tzinfo Objects</A> |
| 308 | </div> |
| 309 | </div> |
| 310 | <hr /> |
| 311 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 312 | </DIV> |
| 313 | <!--End of Navigation Panel--> |
| 314 | <ADDRESS> |
| 315 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 316 | </ADDRESS> |
| 317 | </BODY> |
| 318 | </HTML> |