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,secondandmicrosecond. The arguments are as follows:hour,minute,secondandmicrosecondare integers in the given ranges:0<=hour<240<=minute<600<=second<600<=microsecond<1000000
Each of these arguments will default to
0if omitted.tzinfois adatetime.tzinfoobject, allowing a time to be associated with a particular timezone. If this is not desired, thetzinfocan beNone.foldis a value of either0or1used 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 values0and1represent, respectively, the earlier and later of the two moments with the same wall time representation.
- classmethod fromisoformat(time_string)
Construct a
timeobject 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
0to23.
- minute
The minute of the time, an integer in the range
0to59.
- second
The second of the time, an integer in the range
0to59.
- microsecond
The microsecond of the time, an integer in the range
0to999999.
- tzinfo
The
datetime.tzinfoobject associated with the time, orNoneif no timezone information is associated with the time.
- fold
Used to disambiguate wall times during a repeated interval. The values
0and1represent, 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
timeobject 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.ssssssifmicrosecondis not0). The optionaltimespecargument 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.timedeltaobject, orNoneif the time has no associated timezone.
- tzname()
Return the name of the timezone as a string, or
Noneif the time has no associated timezone.
- utcoffset()
Return the UTC offset as a
datetime.timedeltaobject, orNoneif the time has no associated timezone.