Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / api / datetime-objects.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="api.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="api.html" title='Python/C API Reference Manual' />
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="prev" href="gen-objects.html" />
13<link rel="parent" href="otherObjects.html" />
14<link rel="next" href="initialization.html" />
15<meta name='aesop' content='information' />
16<title>7.5.12 DateTime Objects </title>
17</head>
18<body>
19<DIV CLASS="navigation">
20<div id='top-navigation-panel' xml:id='top-navigation-panel'>
21<table align="center" width="100%" cellpadding="0" cellspacing="2">
22<tr>
23<td class='online-navigation'><a rel="prev" title="7.5.11 Generator Objects"
24 href="gen-objects.html"><img src='../icons/previous.png'
25 border='0' height='32' alt='Previous Page' width='32' /></A></td>
26<td class='online-navigation'><a rel="parent" title="7.5 Other Objects"
27 href="otherObjects.html"><img src='../icons/up.png'
28 border='0' height='32' alt='Up One Level' width='32' /></A></td>
29<td class='online-navigation'><a rel="next" title="8. Initialization, Finalization, and"
30 href="initialization.html"><img src='../icons/next.png'
31 border='0' height='32' alt='Next Page' width='32' /></A></td>
32<td align="center" width="100%">Python/C API Reference Manual</td>
33<td class='online-navigation'><a rel="contents" title="Table of Contents"
34 href="contents.html"><img src='../icons/contents.png'
35 border='0' height='32' alt='Contents' width='32' /></A></td>
36<td class='online-navigation'><img src='../icons/blank.png'
37 border='0' height='32' alt='' width='32' /></td>
38<td class='online-navigation'><a rel="index" title="Index"
39 href="genindex.html"><img src='../icons/index.png'
40 border='0' height='32' alt='Index' width='32' /></A></td>
41</tr></table>
42<div class='online-navigation'>
43<b class="navlabel">Previous:</b>
44<a class="sectref" rel="prev" href="gen-objects.html">7.5.11 Generator Objects</A>
45<b class="navlabel">Up:</b>
46<a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A>
47<b class="navlabel">Next:</b>
48<a class="sectref" rel="next" href="initialization.html">8. Initialization, Finalization, and</A>
49</div>
50<hr /></div>
51</DIV>
52<!--End of Navigation Panel-->
53
54<H2><A NAME="SECTION0095120000000000000000"></A><A NAME="datetime-objects"></A>
55<BR>
567.5.12 DateTime Objects
57</H2>
58
59<P>
60Various date and time objects are supplied by the <tt class="module">datetime</tt>
61module. Before using any of these functions, the header file
62<span class="file">datetime.h</span> must be included in your source (note that this is
63not include by <span class="file">Python.h</span>), and macro <tt class="cfunction">PyDateTime_IMPORT()</tt>
64must be invoked. The macro arranges to put a pointer to a C structure
65in a static variable <code>PyDateTimeAPI</code>, which is used by the following
66macros.
67
68<P>
69Type-check macros:
70
71<P>
72<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-746' xml:id='l2h-746' class="cfunction">PyDate_Check</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
73<dd>
74 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_DateType</tt> or
75 a subtype of <tt class="cdata">PyDateTime_DateType</tt>. <var>ob</var> must not be
76 <tt class="constant">NULL</tt>.
77
78<span class="versionnote">New in version 2.4.</span>
79
80</dd></dl>
81
82<P>
83<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-747' xml:id='l2h-747' class="cfunction">PyDate_CheckExact</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
84<dd>
85 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_DateType</tt>.
86 <var>ob</var> must not be <tt class="constant">NULL</tt>.
87
88<span class="versionnote">New in version 2.4.</span>
89
90</dd></dl>
91
92<P>
93<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-748' xml:id='l2h-748' class="cfunction">PyDateTime_Check</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
94<dd>
95 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_DateTimeType</tt> or
96 a subtype of <tt class="cdata">PyDateTime_DateTimeType</tt>. <var>ob</var> must not be
97 <tt class="constant">NULL</tt>.
98
99<span class="versionnote">New in version 2.4.</span>
100
101</dd></dl>
102
103<P>
104<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-749' xml:id='l2h-749' class="cfunction">PyDateTime_CheckExact</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
105<dd>
106 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_DateTimeType</tt>.
107 <var>ob</var> must not be <tt class="constant">NULL</tt>.
108
109<span class="versionnote">New in version 2.4.</span>
110
111</dd></dl>
112
113<P>
114<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-750' xml:id='l2h-750' class="cfunction">PyTime_Check</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
115<dd>
116 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_TimeType</tt> or
117 a subtype of <tt class="cdata">PyDateTime_TimeType</tt>. <var>ob</var> must not be
118 <tt class="constant">NULL</tt>.
119
120<span class="versionnote">New in version 2.4.</span>
121
122</dd></dl>
123
124<P>
125<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-751' xml:id='l2h-751' class="cfunction">PyTime_CheckExact</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
126<dd>
127 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_TimeType</tt>.
128 <var>ob</var> must not be <tt class="constant">NULL</tt>.
129
130<span class="versionnote">New in version 2.4.</span>
131
132</dd></dl>
133
134<P>
135<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-752' xml:id='l2h-752' class="cfunction">PyDelta_Check</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
136<dd>
137 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_DeltaType</tt> or
138 a subtype of <tt class="cdata">PyDateTime_DeltaType</tt>. <var>ob</var> must not be
139 <tt class="constant">NULL</tt>.
140
141<span class="versionnote">New in version 2.4.</span>
142
143</dd></dl>
144
145<P>
146<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-753' xml:id='l2h-753' class="cfunction">PyDelta_CheckExact</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
147<dd>
148 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_DeltaType</tt>.
149 <var>ob</var> must not be <tt class="constant">NULL</tt>.
150
151<span class="versionnote">New in version 2.4.</span>
152
153</dd></dl>
154
155<P>
156<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-754' xml:id='l2h-754' class="cfunction">PyTZInfo_Check</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
157<dd>
158 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_TZInfoType</tt> or
159 a subtype of <tt class="cdata">PyDateTime_TZInfoType</tt>. <var>ob</var> must not be
160 <tt class="constant">NULL</tt>.
161
162<span class="versionnote">New in version 2.4.</span>
163
164</dd></dl>
165
166<P>
167<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-755' xml:id='l2h-755' class="cfunction">PyTZInfo_CheckExact</tt></b>(</nobr></td><td>PyObject *<var>ob</var>)</td></tr></table></dt>
168<dd>
169 Return true if <var>ob</var> is of type <tt class="cdata">PyDateTime_TZInfoType</tt>.
170 <var>ob</var> must not be <tt class="constant">NULL</tt>.
171
172<span class="versionnote">New in version 2.4.</span>
173
174</dd></dl>
175
176<P>
177Macros to create objects:
178
179<P>
180<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-756' xml:id='l2h-756' class="cfunction">PyDate_FromDate</tt></b>(</nobr></td><td>int <var>year</var>, int <var>month</var>, int <var>day</var>)</td></tr></table></dt>
181<dd>
182 Return a <code>datetime.date</code> object with the specified year, month
183 and day.
184
185<span class="versionnote">New in version 2.4.</span>
186
187</dd></dl>
188
189<P>
190<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-757' xml:id='l2h-757' class="cfunction">PyDateTime_FromDateAndTime</tt></b>(</nobr></td><td>int <var>year</var>, int <var>month</var>,
191 int <var>day</var>, int <var>hour</var>, int <var>minute</var>, int <var>second</var>, int <var>usecond</var>)</td></tr></table></dt>
192<dd>
193 Return a <code>datetime.datetime</code> object with the specified year, month,
194 day, hour, minute, second and microsecond.
195
196<span class="versionnote">New in version 2.4.</span>
197
198</dd></dl>
199
200<P>
201<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-758' xml:id='l2h-758' class="cfunction">PyTime_FromTime</tt></b>(</nobr></td><td>int <var>hour</var>, int <var>minute</var>,
202 int <var>second</var>, int <var>usecond</var>)</td></tr></table></dt>
203<dd>
204 Return a <code>datetime.time</code> object with the specified hour, minute,
205 second and microsecond.
206
207<span class="versionnote">New in version 2.4.</span>
208
209</dd></dl>
210
211<P>
212<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-759' xml:id='l2h-759' class="cfunction">PyDelta_FromDSU</tt></b>(</nobr></td><td>int <var>days</var>, int <var>seconds</var>,
213 int <var>useconds</var>)</td></tr></table></dt>
214<dd>
215 Return a <code>datetime.timedelta</code> object representing the given number
216 of days, seconds and microseconds. Normalization is performed so that
217 the resulting number of microseconds and seconds lie in the ranges
218 documented for <code>datetime.timedelta</code> objects.
219
220<span class="versionnote">New in version 2.4.</span>
221
222</dd></dl>
223
224<P>
225Macros to extract fields from date objects. The argument must be an
226instance of <tt class="cdata">PyDateTime_Date</tt>, including subclasses (such as
227<tt class="cdata">PyDateTime_DateTime</tt>). The argument must not be <tt class="constant">NULL</tt>, and
228the type is not checked:
229
230<P>
231<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-760' xml:id='l2h-760' class="cfunction">PyDateTime_GET_YEAR</tt></b>(</nobr></td><td>PyDateTime_Date *<var>o</var>)</td></tr></table></dt>
232<dd>
233 Return the year, as a positive int.
234
235<span class="versionnote">New in version 2.4.</span>
236
237</dd></dl>
238
239<P>
240<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-761' xml:id='l2h-761' class="cfunction">PyDateTime_GET_MONTH</tt></b>(</nobr></td><td>PyDateTime_Date *<var>o</var>)</td></tr></table></dt>
241<dd>
242 Return the month, as an int from 1 through 12.
243
244<span class="versionnote">New in version 2.4.</span>
245
246</dd></dl>
247
248<P>
249<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-762' xml:id='l2h-762' class="cfunction">PyDateTime_GET_DAY</tt></b>(</nobr></td><td>PyDateTime_Date *<var>o</var>)</td></tr></table></dt>
250<dd>
251 Return the day, as an int from 1 through 31.
252
253<span class="versionnote">New in version 2.4.</span>
254
255</dd></dl>
256
257<P>
258Macros to extract fields from datetime objects. The argument must be an
259instance of <tt class="cdata">PyDateTime_DateTime</tt>, including subclasses.
260The argument must not be <tt class="constant">NULL</tt>, and the type is not checked:
261
262<P>
263<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-763' xml:id='l2h-763' class="cfunction">PyDateTime_DATE_GET_HOUR</tt></b>(</nobr></td><td>PyDateTime_DateTime *<var>o</var>)</td></tr></table></dt>
264<dd>
265 Return the hour, as an int from 0 through 23.
266
267<span class="versionnote">New in version 2.4.</span>
268
269</dd></dl>
270
271<P>
272<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-764' xml:id='l2h-764' class="cfunction">PyDateTime_DATE_GET_MINUTE</tt></b>(</nobr></td><td>PyDateTime_DateTime *<var>o</var>)</td></tr></table></dt>
273<dd>
274 Return the minute, as an int from 0 through 59.
275
276<span class="versionnote">New in version 2.4.</span>
277
278</dd></dl>
279
280<P>
281<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-765' xml:id='l2h-765' class="cfunction">PyDateTime_DATE_GET_SECOND</tt></b>(</nobr></td><td>PyDateTime_DateTime *<var>o</var>)</td></tr></table></dt>
282<dd>
283 Return the second, as an int from 0 through 59.
284
285<span class="versionnote">New in version 2.4.</span>
286
287</dd></dl>
288
289<P>
290<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-766' xml:id='l2h-766' class="cfunction">PyDateTime_DATE_GET_MICROSECOND</tt></b>(</nobr></td><td>PyDateTime_DateTime *<var>o</var>)</td></tr></table></dt>
291<dd>
292 Return the microsecond, as an int from 0 through 999999.
293
294<span class="versionnote">New in version 2.4.</span>
295
296</dd></dl>
297
298<P>
299Macros to extract fields from time objects. The argument must be an
300instance of <tt class="cdata">PyDateTime_Time</tt>, including subclasses.
301The argument must not be <tt class="constant">NULL</tt>, and the type is not checked:
302
303<P>
304<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-767' xml:id='l2h-767' class="cfunction">PyDateTime_TIME_GET_HOUR</tt></b>(</nobr></td><td>PyDateTime_Time *<var>o</var>)</td></tr></table></dt>
305<dd>
306 Return the hour, as an int from 0 through 23.
307
308<span class="versionnote">New in version 2.4.</span>
309
310</dd></dl>
311
312<P>
313<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-768' xml:id='l2h-768' class="cfunction">PyDateTime_TIME_GET_MINUTE</tt></b>(</nobr></td><td>PyDateTime_Time *<var>o</var>)</td></tr></table></dt>
314<dd>
315 Return the minute, as an int from 0 through 59.
316
317<span class="versionnote">New in version 2.4.</span>
318
319</dd></dl>
320
321<P>
322<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-769' xml:id='l2h-769' class="cfunction">PyDateTime_TIME_GET_SECOND</tt></b>(</nobr></td><td>PyDateTime_Time *<var>o</var>)</td></tr></table></dt>
323<dd>
324 Return the second, as an int from 0 through 59.
325
326<span class="versionnote">New in version 2.4.</span>
327
328</dd></dl>
329
330<P>
331<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int&nbsp;<b><tt id='l2h-770' xml:id='l2h-770' class="cfunction">PyDateTime_TIME_GET_MICROSECOND</tt></b>(</nobr></td><td>PyDateTime_Time *<var>o</var>)</td></tr></table></dt>
332<dd>
333 Return the microsecond, as an int from 0 through 999999.
334
335<span class="versionnote">New in version 2.4.</span>
336
337</dd></dl>
338
339<P>
340Macros for the convenience of modules implementing the DB API:
341
342<P>
343<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-771' xml:id='l2h-771' class="cfunction">PyDateTime_FromTimestamp</tt></b>(</nobr></td><td>PyObject *<var>args</var>)</td></tr></table></dt>
344<dd>
345 Create and return a new <code>datetime.datetime</code> object given an argument
346 tuple suitable for passing to <code>datetime.datetime.fromtimestamp()</code>.
347
348<span class="versionnote">New in version 2.4.</span>
349
350</dd></dl>
351
352<P>
353<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject*&nbsp;<b><tt id='l2h-772' xml:id='l2h-772' class="cfunction">PyDate_FromTimestamp</tt></b>(</nobr></td><td>PyObject *<var>args</var>)</td></tr></table></dt>
354<dd>
355 Create and return a new <code>datetime.date</code> object given an argument
356 tuple suitable for passing to <code>datetime.date.fromtimestamp()</code>.
357
358<span class="versionnote">New in version 2.4.</span>
359
360</dd></dl>
361
362<DIV CLASS="navigation">
363<div class='online-navigation'>
364<p></p><hr />
365<table align="center" width="100%" cellpadding="0" cellspacing="2">
366<tr>
367<td class='online-navigation'><a rel="prev" title="7.5.11 Generator Objects"
368 href="gen-objects.html"><img src='../icons/previous.png'
369 border='0' height='32' alt='Previous Page' width='32' /></A></td>
370<td class='online-navigation'><a rel="parent" title="7.5 Other Objects"
371 href="otherObjects.html"><img src='../icons/up.png'
372 border='0' height='32' alt='Up One Level' width='32' /></A></td>
373<td class='online-navigation'><a rel="next" title="8. Initialization, Finalization, and"
374 href="initialization.html"><img src='../icons/next.png'
375 border='0' height='32' alt='Next Page' width='32' /></A></td>
376<td align="center" width="100%">Python/C API Reference Manual</td>
377<td class='online-navigation'><a rel="contents" title="Table of Contents"
378 href="contents.html"><img src='../icons/contents.png'
379 border='0' height='32' alt='Contents' width='32' /></A></td>
380<td class='online-navigation'><img src='../icons/blank.png'
381 border='0' height='32' alt='' width='32' /></td>
382<td class='online-navigation'><a rel="index" title="Index"
383 href="genindex.html"><img src='../icons/index.png'
384 border='0' height='32' alt='Index' width='32' /></A></td>
385</tr></table>
386<div class='online-navigation'>
387<b class="navlabel">Previous:</b>
388<a class="sectref" rel="prev" href="gen-objects.html">7.5.11 Generator Objects</A>
389<b class="navlabel">Up:</b>
390<a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A>
391<b class="navlabel">Next:</b>
392<a class="sectref" rel="next" href="initialization.html">8. Initialization, Finalization, and</A>
393</div>
394</div>
395<hr />
396<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
397</DIV>
398<!--End of Navigation Panel-->
399<ADDRESS>
400See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
401</ADDRESS>
402</BODY>
403</HTML>