1
<?xml version="1.0" encoding="ascii"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
"DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
<link rel="stylesheet" href="epydoc.css" type="text/css" />
8
<script type="text/javascript" src="epydoc.js"></script>
11
<body bgcolor="white" text="black" link="blue" vlink="#204080"
13
<!-- ==================== NAVIGATION BAR ==================== -->
14
<table class="navbar" border="0" width="100%" cellpadding="0"
15
bgcolor="#a0c0ff" cellspacing="0">
18
<th> <a
19
href="etl-module.html">Home</a> </th>
22
<th> <a
23
href="module-tree.html">Trees</a> </th>
26
<th> <a
27
href="identifier-index.html">Indices</a> </th>
30
<th> <a
31
href="help.html">Help</a> </th>
33
<th class="navbar" width="100%"></th>
36
<table width="100%" cellpadding="0" cellspacing="0">
39
<span class="breadcrumbs">
44
<table cellpadding="0" cellspacing="0">
45
<!-- hide/show private -->
46
<tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
47
onclick="toggle_private();">hide private</a>]</span></td></tr>
48
<tr><td align="right"><span class="options"
49
>[<a href="frames.html" target="_top">frames</a
50
>] | <a href="time-module.html"
51
target="_top">no frames</a>]</span></td></tr>
56
<!-- ==================== MODULE DESCRIPTION ==================== -->
57
<h1 class="epydoc">Module time</h1><br /><br />
58
<pre class="literalblock">
59
This module provides various functions to manipulate time values.
61
There are two standard representations of time. One is the number
62
of seconds since the Epoch, in UTC (a.k.a. GMT). It may be an integer
63
or a floating point number (to represent fractions of seconds).
64
The Epoch is system-defined; on Unix, it is generally January 1st, 1970.
65
The actual value can be retrieved by calling gmtime(0).
67
The other representation is a tuple of 9 integers giving local time.
69
year (four digits, e.g. 1998)
75
weekday (0-6, Monday is 0)
76
Julian day (day in the year, 1-366)
77
DST (Daylight Savings Time) flag (-1, 0 or 1)
78
If the DST flag is 0, the time is given in the regular time zone;
79
if it is 1, the time is given in the DST time zone;
80
if it is -1, mktime() should guess based on the date and time.
84
timezone -- difference in seconds between UTC and local standard time
85
altzone -- difference in seconds between UTC and local DST time
86
daylight -- whether local time should reflect DST
87
tzname -- tuple of (standard time zone name, DST time zone name)
91
time() -- return current time in seconds since the Epoch as a float
92
clock() -- return CPU time since process start as a float
93
sleep() -- delay for a number of seconds given as a float
94
gmtime() -- convert seconds since Epoch to UTC tuple
95
localtime() -- convert seconds since Epoch to local time tuple
96
asctime() -- convert time tuple to string
97
ctime() -- convert time in seconds to string
98
mktime() -- convert local time tuple to seconds since Epoch
99
strftime() -- convert time tuple to string according to format specification
100
strptime() -- parse string to time tuple according to format specification
101
tzset() -- change the local timezone
105
<!-- ==================== CLASSES ==================== -->
106
<a name="section-Classes"></a>
107
<table class="summary" border="1" cellpadding="3"
108
cellspacing="0" width="100%" bgcolor="white">
109
<tr bgcolor="#70b0f0" class="table-header">
110
<td colspan="2" class="table-header">
111
<table border="0" cellpadding="0" cellspacing="0" width="100%">
113
<td align="left"><span class="table-header">Classes</span></td>
114
<td align="right" valign="top"
115
><span class="options">[<a href="#section-Classes"
116
class="privatelink" onclick="toggle_private();"
117
>hide private</a>]</span></td>
123
<td width="15%" align="right" valign="top" class="summary">
124
<span class="summary-type"> </span>
125
</td><td class="summary">
126
<a href="time.struct_time-class.html" class="summary-name">struct_time</a>
130
<!-- ==================== FUNCTIONS ==================== -->
131
<a name="section-Functions"></a>
132
<table class="summary" border="1" cellpadding="3"
133
cellspacing="0" width="100%" bgcolor="white">
134
<tr bgcolor="#70b0f0" class="table-header">
135
<td colspan="2" class="table-header">
136
<table border="0" cellpadding="0" cellspacing="0" width="100%">
138
<td align="left"><span class="table-header">Functions</span></td>
139
<td align="right" valign="top"
140
><span class="options">[<a href="#section-Functions"
141
class="privatelink" onclick="toggle_private();"
142
>hide private</a>]</span></td>
148
<td width="15%" align="right" valign="top" class="summary">
149
<span class="summary-type"> </span>
150
</td><td class="summary">
151
<table width="100%" cellpadding="0" cellspacing="0" border="0">
153
<td><span class="summary-sig"><a href="time-module.html#asctime" class="summary-sig-name">asctime</a>(<span class="summary-sig-arg">tuple</span>=<span class="summary-sig-default">...</span>)</span><br />
154
Convert a time tuple to a string, e.g.</td>
155
<td align="right" valign="top">
165
<td width="15%" align="right" valign="top" class="summary">
166
<span class="summary-type"> </span>
167
</td><td class="summary">
168
<table width="100%" cellpadding="0" cellspacing="0" border="0">
170
<td><span class="summary-sig"><a href="time-module.html#clock" class="summary-sig-name">clock</a>()</span><br />
171
Return the CPU time or real time since the start of the process or
172
since the first call to clock().</td>
173
<td align="right" valign="top">
183
<td width="15%" align="right" valign="top" class="summary">
184
<span class="summary-type"> </span>
185
</td><td class="summary">
186
<table width="100%" cellpadding="0" cellspacing="0" border="0">
188
<td><span class="summary-sig"><a href="time-module.html#ctime" class="summary-sig-name">ctime</a>(<span class="summary-sig-arg">seconds</span>)</span><br />
189
Convert a time in seconds since the Epoch to a string in local
191
<td align="right" valign="top">
201
<td width="15%" align="right" valign="top" class="summary">
202
<span class="summary-type"> </span>
203
</td><td class="summary">
204
<table width="100%" cellpadding="0" cellspacing="0" border="0">
206
<td><span class="summary-sig"><a href="time-module.html#gmtime" class="summary-sig-name">gmtime</a>(<span class="summary-sig-arg">seconds</span>=<span class="summary-sig-default">...</span>)</span><br />
207
tm_sec, tm_wday, tm_yday, tm_isdst)
209
Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.</td>
210
<td align="right" valign="top">
220
<td width="15%" align="right" valign="top" class="summary">
221
<span class="summary-type"> </span>
222
</td><td class="summary">
223
<table width="100%" cellpadding="0" cellspacing="0" border="0">
225
<td><span class="summary-sig"><a href="time-module.html#localtime" class="summary-sig-name">localtime</a>(<span class="summary-sig-arg">seconds</span>=<span class="summary-sig-default">...</span>)</span><br />
226
Convert seconds since the Epoch to a time tuple expressing local
228
<td align="right" valign="top">
238
<td width="15%" align="right" valign="top" class="summary">
239
<span class="summary-type"> </span>
240
</td><td class="summary">
241
<table width="100%" cellpadding="0" cellspacing="0" border="0">
243
<td><span class="summary-sig"><a href="time-module.html#mktime" class="summary-sig-name">mktime</a>(<span class="summary-sig-arg">tuple</span>)</span><br />
244
Convert a time tuple in local time to seconds since the Epoch.</td>
245
<td align="right" valign="top">
255
<td width="15%" align="right" valign="top" class="summary">
256
<span class="summary-type"> </span>
257
</td><td class="summary">
258
<table width="100%" cellpadding="0" cellspacing="0" border="0">
260
<td><span class="summary-sig"><a href="time-module.html#sleep" class="summary-sig-name">sleep</a>(<span class="summary-sig-arg">seconds</span>)</span><br />
261
Delay execution for a given number of seconds.</td>
262
<td align="right" valign="top">
272
<td width="15%" align="right" valign="top" class="summary">
273
<span class="summary-type"> </span>
274
</td><td class="summary">
275
<table width="100%" cellpadding="0" cellspacing="0" border="0">
277
<td><span class="summary-sig"><a href="time-module.html#strftime" class="summary-sig-name">strftime</a>(<span class="summary-sig-arg">format</span>,
278
<span class="summary-sig-arg">tuple</span>=<span class="summary-sig-default">...</span>)</span><br />
279
Convert a time tuple to a string according to a format
281
<td align="right" valign="top">
291
<td width="15%" align="right" valign="top" class="summary">
292
<span class="summary-type"> </span>
293
</td><td class="summary">
294
<table width="100%" cellpadding="0" cellspacing="0" border="0">
296
<td><span class="summary-sig"><a href="time-module.html#strptime" class="summary-sig-name">strptime</a>(<span class="summary-sig-arg">string</span>,
297
<span class="summary-sig-arg">format</span>)</span><br />
298
Parse a string to a time tuple according to a format
300
<td align="right" valign="top">
310
<td width="15%" align="right" valign="top" class="summary">
311
<span class="summary-type"> </span>
312
</td><td class="summary">
313
<table width="100%" cellpadding="0" cellspacing="0" border="0">
315
<td><span class="summary-sig"><a href="time-module.html#time" class="summary-sig-name">time</a>()</span><br />
316
Return the current time in seconds since the Epoch.</td>
317
<td align="right" valign="top">
327
<td width="15%" align="right" valign="top" class="summary">
328
<span class="summary-type"> </span>
329
</td><td class="summary">
330
<table width="100%" cellpadding="0" cellspacing="0" border="0">
332
<td><span class="summary-sig"><a href="time-module.html#tzset" class="summary-sig-name">tzset</a>(<span class="summary-sig-arg">zone</span>)</span><br />
333
Initialize, or reinitialize, the local timezone to the value
334
stored in os.environ['TZ'].</td>
335
<td align="right" valign="top">
345
<!-- ==================== VARIABLES ==================== -->
346
<a name="section-Variables"></a>
347
<table class="summary" border="1" cellpadding="3"
348
cellspacing="0" width="100%" bgcolor="white">
349
<tr bgcolor="#70b0f0" class="table-header">
350
<td colspan="2" class="table-header">
351
<table border="0" cellpadding="0" cellspacing="0" width="100%">
353
<td align="left"><span class="table-header">Variables</span></td>
354
<td align="right" valign="top"
355
><span class="options">[<a href="#section-Variables"
356
class="privatelink" onclick="toggle_private();"
357
>hide private</a>]</span></td>
363
<td width="15%" align="right" valign="top" class="summary">
364
<span class="summary-type"> </span>
365
</td><td class="summary">
366
<a name="accept2dyear"></a><span class="summary-name">accept2dyear</span> = <code title="1">1</code>
370
<td width="15%" align="right" valign="top" class="summary">
371
<span class="summary-type"> </span>
372
</td><td class="summary">
373
<a name="altzone"></a><span class="summary-name">altzone</span> = <code title="-19800">-19800</code>
377
<td width="15%" align="right" valign="top" class="summary">
378
<span class="summary-type"> </span>
379
</td><td class="summary">
380
<a name="daylight"></a><span class="summary-name">daylight</span> = <code title="0">0</code>
384
<td width="15%" align="right" valign="top" class="summary">
385
<span class="summary-type"> </span>
386
</td><td class="summary">
387
<a name="timezone"></a><span class="summary-name">timezone</span> = <code title="-19800">-19800</code>
391
<td width="15%" align="right" valign="top" class="summary">
392
<span class="summary-type"> </span>
393
</td><td class="summary">
394
<a name="tzname"></a><span class="summary-name">tzname</span> = <code title="('IST', 'IST')"><code class="variable-group">(</code><code class="variable-quote">'</code><code class="variable-string">IST</code><code class="variable-quote">'</code><code class="variable-op">, </code><code class="variable-quote">'</code><code class="variable-string">IST</code><code class="variable-quote">'</code><code class="variable-group">)</code></code>
398
<!-- ==================== FUNCTION DETAILS ==================== -->
399
<a name="section-FunctionDetails"></a>
400
<table class="details" border="1" cellpadding="3"
401
cellspacing="0" width="100%" bgcolor="white">
402
<tr bgcolor="#70b0f0" class="table-header">
403
<td colspan="2" class="table-header">
404
<table border="0" cellpadding="0" cellspacing="0" width="100%">
406
<td align="left"><span class="table-header">Function Details</span></td>
407
<td align="right" valign="top"
408
><span class="options">[<a href="#section-FunctionDetails"
409
class="privatelink" onclick="toggle_private();"
410
>hide private</a>]</span></td>
416
<a name="asctime"></a>
418
<table class="details" border="1" cellpadding="3"
419
cellspacing="0" width="100%" bgcolor="white">
421
<table width="100%" cellpadding="0" cellspacing="0" border="0">
422
<tr valign="top"><td>
423
<h3 class="epydoc"><span class="sig"><span class="sig-name">asctime</span>(<span class="sig-arg">tuple</span>=<span class="sig-default">...</span>)</span>
425
</td><td align="right" valign="top"
430
Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.
431
When the time tuple is not present, current time as returned by
435
<dd><pre class="literalblock">
444
<table class="details" border="1" cellpadding="3"
445
cellspacing="0" width="100%" bgcolor="white">
447
<table width="100%" cellpadding="0" cellspacing="0" border="0">
448
<tr valign="top"><td>
449
<h3 class="epydoc"><span class="sig"><span class="sig-name">clock</span>()</span>
451
</td><td align="right" valign="top"
456
Return the CPU time or real time since the start of the process or
457
since the first call to clock(). This has as much precision as the
461
<dd><pre class="literalblock">
462
floating point number
470
<table class="details" border="1" cellpadding="3"
471
cellspacing="0" width="100%" bgcolor="white">
473
<table width="100%" cellpadding="0" cellspacing="0" border="0">
474
<tr valign="top"><td>
475
<h3 class="epydoc"><span class="sig"><span class="sig-name">ctime</span>(<span class="sig-arg">seconds</span>)</span>
477
</td><td align="right" valign="top"
482
Convert a time in seconds since the Epoch to a string in local time.
483
This is equivalent to asctime(localtime(seconds)). When the time tuple is
484
not present, current time as returned by localtime() is used.
487
<dd><pre class="literalblock">
494
<a name="gmtime"></a>
496
<table class="details" border="1" cellpadding="3"
497
cellspacing="0" width="100%" bgcolor="white">
499
<table width="100%" cellpadding="0" cellspacing="0" border="0">
500
<tr valign="top"><td>
501
<h3 class="epydoc"><span class="sig"><span class="sig-name">gmtime</span>(<span class="sig-arg">seconds</span>=<span class="sig-default">...</span>)</span>
503
</td><td align="right" valign="top"
508
<pre class="literalblock">
509
tm_sec, tm_wday, tm_yday, tm_isdst)
511
Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.
512
GMT). When 'seconds' is not passed in, convert the current time instead.
517
<dd><pre class="literalblock">
518
(tm_year, tm_mon, tm_mday, tm_hour, tm_min,
524
<a name="localtime"></a>
526
<table class="details" border="1" cellpadding="3"
527
cellspacing="0" width="100%" bgcolor="white">
529
<table width="100%" cellpadding="0" cellspacing="0" border="0">
530
<tr valign="top"><td>
531
<h3 class="epydoc"><span class="sig"><span class="sig-name">localtime</span>(<span class="sig-arg">seconds</span>=<span class="sig-default">...</span>)</span>
533
</td><td align="right" valign="top"
538
Convert seconds since the Epoch to a time tuple expressing local time.
539
When 'seconds' is not passed in, convert the current time instead.
542
<dd><pre class="literalblock">
543
(tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst)
549
<a name="mktime"></a>
551
<table class="details" border="1" cellpadding="3"
552
cellspacing="0" width="100%" bgcolor="white">
554
<table width="100%" cellpadding="0" cellspacing="0" border="0">
555
<tr valign="top"><td>
556
<h3 class="epydoc"><span class="sig"><span class="sig-name">mktime</span>(<span class="sig-arg">tuple</span>)</span>
558
</td><td align="right" valign="top"
563
Convert a time tuple in local time to seconds since the Epoch.
566
<dd><pre class="literalblock">
567
floating point number
575
<table class="details" border="1" cellpadding="3"
576
cellspacing="0" width="100%" bgcolor="white">
578
<table width="100%" cellpadding="0" cellspacing="0" border="0">
579
<tr valign="top"><td>
580
<h3 class="epydoc"><span class="sig"><span class="sig-name">sleep</span>(<span class="sig-arg">seconds</span>)</span>
582
</td><td align="right" valign="top"
587
Delay execution for a given number of seconds. The argument may be a
588
floating point number for subsecond precision.
593
<a name="strftime"></a>
595
<table class="details" border="1" cellpadding="3"
596
cellspacing="0" width="100%" bgcolor="white">
598
<table width="100%" cellpadding="0" cellspacing="0" border="0">
599
<tr valign="top"><td>
600
<h3 class="epydoc"><span class="sig"><span class="sig-name">strftime</span>(<span class="sig-arg">format</span>,
601
<span class="sig-arg">tuple</span>=<span class="sig-default">...</span>)</span>
603
</td><td align="right" valign="top"
608
Convert a time tuple to a string according to a format specification.
609
See the library reference manual for formatting codes. When the time
610
tuple is not present, current time as returned by localtime() is
614
<dd><pre class="literalblock">
621
<a name="strptime"></a>
623
<table class="details" border="1" cellpadding="3"
624
cellspacing="0" width="100%" bgcolor="white">
626
<table width="100%" cellpadding="0" cellspacing="0" border="0">
627
<tr valign="top"><td>
628
<h3 class="epydoc"><span class="sig"><span class="sig-name">strptime</span>(<span class="sig-arg">string</span>,
629
<span class="sig-arg">format</span>)</span>
631
</td><td align="right" valign="top"
636
Parse a string to a time tuple according to a format specification.
637
See the library reference manual for formatting codes (same as
641
<dd><pre class="literalblock">
650
<table class="details" border="1" cellpadding="3"
651
cellspacing="0" width="100%" bgcolor="white">
653
<table width="100%" cellpadding="0" cellspacing="0" border="0">
654
<tr valign="top"><td>
655
<h3 class="epydoc"><span class="sig"><span class="sig-name">time</span>()</span>
657
</td><td align="right" valign="top"
662
Return the current time in seconds since the Epoch. Fractions of a
663
second may be present if the system clock provides them.
666
<dd><pre class="literalblock">
667
floating point number
675
<table class="details" border="1" cellpadding="3"
676
cellspacing="0" width="100%" bgcolor="white">
678
<table width="100%" cellpadding="0" cellspacing="0" border="0">
679
<tr valign="top"><td>
680
<h3 class="epydoc"><span class="sig"><span class="sig-name">tzset</span>(<span class="sig-arg">zone</span>)</span>
682
</td><td align="right" valign="top"
687
Initialize, or reinitialize, the local timezone to the value stored in
688
os.environ['TZ']. The TZ environment variable should be specified in
689
standard Unix timezone format as documented in the tzset man page (eg.
690
'US/Eastern', 'Europe/Amsterdam'). Unknown timezones will silently fall
691
back to UTC. If the TZ environment variable is not set, the local
692
timezone is set to the systems best guess of wallclock time. Changing the
693
TZ environment variable without calling tzset *may* change the local
694
timezone used by methods such as localtime, but this behaviour should not
701
<!-- ==================== NAVIGATION BAR ==================== -->
702
<table class="navbar" border="0" width="100%" cellpadding="0"
703
bgcolor="#a0c0ff" cellspacing="0">
706
<th> <a
707
href="etl-module.html">Home</a> </th>
710
<th> <a
711
href="module-tree.html">Trees</a> </th>
714
<th> <a
715
href="identifier-index.html">Indices</a> </th>
718
<th> <a
719
href="help.html">Help</a> </th>
721
<th class="navbar" width="100%"></th>
724
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
726
<td align="left" class="footer">
727
Generated by Epydoc 3.0beta1 on Wed Apr 29 20:37:21 2009
729
<td align="right" class="footer">
730
<a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
735
<script type="text/javascript">
737
// Private objects are initially displayed (because if
738
// javascript is turned off then we want them to be
739
// visible); but by default, we want to hide them. So hide
740
// them unless we have a cookie that says to show them.