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

28.4. time: Clock and calendar functions

This module provides minimal time and date functions. For a newer and more complete module, see the datetime module.

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 old 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:

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