Epoch time is the time in seconds since some arbitrary starting point. For example, Unix measures time in seconds since January 1, 1970.
UTC is Coordinated Universal Time, the time on the zero meridian (which goes through London).
DST refers to Daylight Savings Time.
A time tuple is a 9-tuple
with these elements, all integers:T
| Four-digit year. | | Second, in [0,59]. |
| Month, 1 for January, 12 for December. | | Day of week, 0 for Monday, 6 for Sunday. |
| Day of month, in [1,31]. | | Ordinal day of the year, in [1,366]. |
| Hour, in [0,23]. | | DST flag: 1
if the time is DST, 0
if it is not DST, and -1
if unknown. |
| Minute, in [0,59]. |
Contents of the time module:
altzoneThe local DST offset, in seconds west of UTC (negative for east of UTC).
asctime([T])For a time-tuple , returns a string of exactly
24 characters with this format:T
"Thu Jun 12 15:25:31 1997"
The default time is now.
clock()The accumulated CPU time of the current process in seconds, as a float.
ctime([E])Converts an epoch time to a string with the
same format as Easctime(). The default time is now.
daylightNonzero if there is a DST value defined locally.
gmtime([E])Returns the time-tuple corresponding to UTC at epoch
time ; the DST flag will be zero. The default time is
now.E
localtime([E])Returns the time-tuple corresponding to local
time at epoch time . The default time
is now.E
mktime(T)Converts a time-tuple to epoch time as a
float, where T is the
local time.T
sleep(s)Suspend execution of the current process for
seconds, where s can be a float or
integer.s
strftime(f[,t])Time formatting function; formats
a time-tuple according to format
string t. The default time
f
is now. As with the
string format
operator, format codes start with
t%, and other text appears
unchanged in the result. See the
table of codes
below.
time()The current epoch time, as a float.
timezoneThe local non-DST time zone as an offset in seconds west of UTC (negative for east of UTC). This value applies when daylight savings time is not in effect.
tznameA 2-tuple (,
s) where d is the name of the non-DST
time zone locally and s is the name of the
local DST time zone. For example, in Socorro, NM,
you get d('MST', 'MDT').
Format codes for the strftime
function include:
%a | Abbreviated weekday name, e.g.,
"Tue". |
%A | Full weekday name, e.g.,
"Tuesday". |
%b | Abbreviated month name,
e.g., "Jul". |
%B | Full month name, e.g.,
"July". |
%d | Day of the month, two digits with
left zero fill; e.g.
"03". |
%H | Hour on the 24-hour clock, two digits with zero fill. |
%I | Hour on the 12-hour clock, two digits with zero fill. |
%j | Day of the year as a decimal number, three digits with zero fill, e.g. "366". |
%m | Decimal month, two digits with zero fill. |
%M | Minute, two digits with zero fill. |
%p | Either "AM"
or "PM". Midnight
is considered AM and noon PM. |
%S | Second, two digits with zero fill. |
%w | Numeric weekday: 0 for Sunday, 6 for Saturday. |
%y | Two-digit year. Not recommended! |
%Y | Four-digit year. |
%Z | If there is a time zone, a string
representing that zone; e.g.,
"PST". |
%% | Outputs the character %. |