class time – Represent a time
A representation of a time, assuming that every day is composed of 24 hours, each hour composed of 60 minutes, and each minute composed of 60 seconds.
N.B. time objects have no notion of “leap seconds”.
time
objects support equality and comparison operators.
- class datetime.time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)
Construct a time object representing a given
hour
,minute
,second
andmicrosecond
. The arguments are as follows:hour
,minute
,second
andmicrosecond
are integers in the given ranges:0
<=hour
<24
0
<=minute
<60
0
<=second
<60
0
<=microsecond
<1000000
Each of these arguments will default to
0
if omitted.tzinfo
is adatetime.tzinfo
object, allowing a time to be associated with a particular timezone. If this is not desired, thetzinfo
can beNone
.fold
is a value of either0
or1
used to disambiguate wall times during a repeated interval. A repeated interval occurs when clocks are rolled back at the end of daylight saving time, or when the UTC offset for the current zone is decreased for political reasons. The values0
and1
represent, respectively, the earlier and later of the two moments with the same wall time representation.
- classmethod fromisoformat(time_string)
Construct a
time
object from a string in ISO 8601 format:from datetime import time t = time.fromisoformat('07:55:27.999999')
- 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)
.
- hour
The hour of the time, an integer in the range
0
to23
.
- minute
The minute of the time, an integer in the range
0
to59
.
- second
The second of the time, an integer in the range
0
to59
.
- microsecond
The microsecond of the time, an integer in the range
0
to999999
.
- tzinfo
The
datetime.tzinfo
object associated with the time, orNone
if no timezone information is associated with the time.
- fold
Used to disambiguate wall times during a repeated interval. The values
0
and1
represent, respectively, the earlier and later of the two moments with the same wall time representation.
- replace(hour=self.hour, minute=self.minute, second=self.second, microsecond=self.microsecond, tzinfo=self.tzinfo, *, fold=0)
Return a new
time
object with the same values as the existing time object, but with the specified parameters updated.
- isoformat(timespec='auto')
Return a string representing the time in ISO 8601 format.
By default, this will output time in the format
HH-MM-SS
(orHH-MM-SS.ssssss
ifmicrosecond
is not0
). The optionaltimespec
argument can be used to specify the number of digits to include in the output string:'hours'
:HH
'minutes'
:HH:MM
'seconds'
:HH:MM:SS
'milliseconds'
:HH:MM:SS.sss
'microseconds'
:HH:MM:SS.ssssss
- tuple()
Return the time as a 6-tuple
(hour, minute, second, microsecond, tzinfo, fold)
.
- dst()
Return the daylight savings time offset as a
datetime.timedelta
object, orNone
if the time has no associated timezone.
- tzname()
Return the name of the timezone as a string, or
None
if the time has no associated timezone.
- utcoffset()
Return the UTC offset as a
datetime.timedelta
object, orNone
if the time has no associated timezone.