This module provides various functions to manipulate time values.
There are two standard representations of time. One is the number
of seconds since the Epoch, in UTC (a.k.a. GMT). It may be an integer
or a floating point number (to represent fractions of seconds).
The Epoch is system-defined; on Unix, it is generally January 1st, 1970.
The actual value can be retrieved by calling gmtime(0).
The other representation is a tuple of 9 integers giving local time.
The tuple items are:
year (four digits, e.g. 1998)
weekday (0-6, Monday is 0)
Julian day (day in the year, 1-366)
DST (Daylight Savings Time) flag (-1, 0 or 1)
If the DST flag is 0, the time is given in the regular time zone;
if it is 1, the time is given in the DST time zone;
if it is -1, mktime() should guess based on the date and time.
timezone -- difference in seconds between UTC and local standard time
altzone -- difference in seconds between UTC and local DST time
daylight -- whether local time should reflect DST
tzname -- tuple of (standard time zone name, DST time zone name)
time() -- return current time in seconds since the Epoch as a float
clock() -- return CPU time since process start as a float
sleep() -- delay for a number of seconds given as a float
gmtime() -- convert seconds since Epoch to UTC tuple
localtime() -- convert seconds since Epoch to local time tuple
asctime() -- convert time tuple to string
ctime() -- convert time in seconds to string
mktime() -- convert local time tuple to seconds since Epoch
strftime() -- convert time tuple to string according to format specification
strptime() -- parse string to time tuple according to format specification
tzset() -- change the local timezone
||The time value as returned by gmtime(), localtime(), and strptime(), and|
accepted by asctime(), mktime() and strftime(). May be considered as a
sequence of 9 integers.
Note that several fields' values are not the same as those defined by
the C language standard for struct tm. For example, the value of the
field tm_year is the actual year, not year - 1900. See individual
fields' descriptions for details.
||Methods defined here:|
- x.__add__(y) <==> x+y
- x.__contains__(y) <==> y in x
- x.__eq__(y) <==> x==y
- x.__ge__(y) <==> x>=y
- x.__getitem__(y) <==> x[y]
- x.__getslice__(i, j) <==> x[i:j]
Use of negative indices is not supported.
- x.__gt__(y) <==> x>y
- x.__hash__() <==> hash(x)
- x.__le__(y) <==> x<=y
- x.__len__() <==> len(x)
- x.__lt__(y) <==> x<y
- x.__mul__(n) <==> x*n
- x.__ne__(y) <==> x!=y
- x.__repr__() <==> repr(x)
- x.__rmul__(n) <==> n*x
Data descriptors defined here:
- hours, range [0, 23]
- 1 if summer time is in effect, 0 if not, and -1 if unknown
- day of month, range [1, 31]
- minutes, range [0, 59]
- month of year, range [1, 12]
- seconds, range [0, 61])
- day of week, range [0, 6], Monday is 0
- day of year, range [1, 366]
- year, for example, 1993
Data and other attributes defined here:
- __new__ = <built-in method __new__ of type object>
- T.__new__(S, ...) -> a new object with type S, a subtype of T
- n_fields = 9
- n_sequence_fields = 9
- n_unnamed_fields = 0
- asctime([tuple]) -> string
Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.
When the time tuple is not present, current time as returned by localtime()
- clock() -> floating point number
Return the CPU time or real time since the start of the process or since
the first call to clock(). This has as much precision as the system
- ctime(seconds) -> string
Convert a time in seconds since the Epoch to a string in local time.
This is equivalent to asctime(localtime(seconds)). When the time tuple is
not present, current time as returned by localtime() is used.
- gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,
tm_sec, tm_wday, tm_yday, tm_isdst)
Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.
GMT). When 'seconds' is not passed in, convert the current time instead.
- localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,
Convert seconds since the Epoch to a time tuple expressing local time.
When 'seconds' is not passed in, convert the current time instead.
- mktime(tuple) -> floating point number
Convert a time tuple in local time to seconds since the Epoch.
Delay execution for a given number of seconds. The argument may be
a floating point number for subsecond precision.
- strftime(format[, tuple]) -> string
Convert a time tuple to a string according to a format specification.
See the library reference manual for formatting codes. When the time tuple
is not present, current time as returned by localtime() is used.
- strptime(string, format) -> struct_time
Parse a string to a time tuple according to a format specification.
See the library reference manual for formatting codes (same as strftime()).
- time() -> floating point number
Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.
Initialize, or reinitialize, the local timezone to the value stored in
os.environ['TZ']. The TZ environment variable should be specified in
standard Unix timezone format as documented in the tzset man page
(eg. 'US/Eastern', 'Europe/Amsterdam'). Unknown timezones will silently
fall back to UTC. If the TZ environment variable is not set, the local
timezone is set to the systems best guess of wallclock time.
Changing the TZ environment variable without calling tzset *may* change
the local timezone used by methods such as localtime, but this behaviour
should not be relied on.
||accept2dyear = 1|
altzone = -32400
daylight = 0
timezone = -32400
tzname = ('JST', 'JST')