Next / Previous / Contents / TCC Help System / NM Tech homepage

20.8. The time module: dates and times

A time tuple is a 9-tuple T with these elements, all integers:

T[0]Four-digit year.T[5]Second, in [0,59].
T[1]Month, 1 for January, 12 for December.T[6]Day of week, 0 for Monday, 6 for Sunday.
T[2]Day of month, in [1,31].T[7]Ordinal day of the year, in [1,366].
T[3]Hour, in [0,23].T[8]DST flag: 1 if the time is DST, 0 if it is not DST, and -1 if unknown.
T[4]Minute, in [0,59].  

Contents of the time module:

altzone

The local DST offset, in seconds west of UTC (negative for east of UTC).

asctime([T])

For a time-tuple T, returns a string of exactly 24 characters with this format:

"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 E to a string with the same format as asctime(). The default time is now.

daylight

Nonzero if there is a DST value defined locally.

gmtime([E])

Returns the time-tuple corresponding to UTC at epoch time E; the DST flag will be zero. The default time is now.

localtime([E])

Returns the time-tuple corresponding to local time at epoch time E. The default time is now.

mktime(T)

Converts a time-tuple T to epoch time as a float, where T is the local time.

sleep(s)

Suspend execution of the current process for s seconds, where s can be a float or integer.

strftime(f[,t])

Time formatting function; formats a time-tuple t according to format string f. The default time t is now. As with the string format operator, format codes start with %, and other text appears unchanged in the result. See the table of codes below.

time()

The current epoch time, as a float.

timezone

The 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.

tzname

A 2-tuple (s, d) where s is the name of the non-DST time zone locally and d is the name of the local DST time zone. For example, in Socorro, NM, you get ('MST', 'MDT').

Format codes for the strftime function include:

%aAbbreviated weekday name, e.g., "Tue".
%AFull weekday name, e.g., "Tuesday".
%bAbbreviated month name, e.g., "Jul".
%BFull month name, e.g., "July".
%dDay of the month, two digits with left zero fill; e.g. "03".
%HHour on the 24-hour clock, two digits with zero fill.
%IHour on the 12-hour clock, two digits with zero fill.
%jDay of the year as a decimal number, three digits with zero fill, e.g. "366".
%mDecimal month, two digits with zero fill.
%MMinute, two digits with zero fill.
%pEither "AM" or "PM". Midnight is considered AM and noon PM.
%SSecond, two digits with zero fill.
%wNumeric weekday: 0 for Sunday, 6 for Saturday.
%yTwo-digit year. Not recommended!
%YFour-digit year.
%ZIf there is a time zone, a string representing that zone; e.g., "PST".
%%Outputs the character %.