6.9.5 time Objects

A time object represents a (local) time of day, independent of any particular day, and subject to adjustment via a tzinfo object.

class time( hour[, minute[, second[, microsecond[, tzinfo]]]])
All arguments are optional. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints or longs, in the following ranges:

If an argument outside those ranges is given, ValueError is raised. All default to 0 except tzinfo, which defaults to None.

Class attributes:

min
The earliest representable time, time(0, 0, 0, 0).

max
The latest representable time, time(23, 59, 59, 999999).

resolution
The smallest possible difference between non-equal time objects, timedelta(microseconds=1), although note that arithmetic on time objects is not supported.

Instance attributes (read-only):

hour
In range(24).

minute
In range(60).

second
In range(60).

microsecond
In range(1000000).

tzinfo
The object passed as the tzinfo argument to the time constructor, or None if none was passed.

Supported operations:

Instance methods:

replace( [hour[, minute[, second[, microsecond[, tzinfo]]]]])
Return a time with the same value, except for those members given new values by whichever keyword arguments are specified. Note that tzinfo=None can be specified to create a naive time from an aware time, without conversion of the time members.

isoformat( )
Return a string representing the time in ISO 8601 format, HH:MM:SS.mmmmmm or, if self.microsecond is 0, HH:MM:SS If utcoffset() does not return None, a 6-character string is appended, giving the UTC offset in (signed) hours and minutes: HH:MM:SS.mmmmmm+HH:MM or, if self.microsecond is 0, HH:MM:SS+HH:MM

__str__( )
For a time t, str(t) is equivalent to t.isoformat().

strftime( format)
Return a string representing the time, controlled by an explicit format string. See the section on strftime() behavior.

utcoffset( )
If tzinfo is None, returns None, else returns self.tzinfo.utcoffset(None), and raises an exception if the latter doesn't return None or a timedelta object representing a whole number of minutes with magnitude less than one day.

dst( )
If tzinfo is None, returns None, else returns self.tzinfo.dst(None), and raises an exception if the latter doesn't return None, or a timedelta object representing a whole number of minutes with magnitude less than one day.

tzname( )
If tzinfo is None, returns None, else returns self.tzinfo.tzname(None), or raises an exception if the latter doesn't return None or a string object.

See About this document... for information on suggesting changes.