The time class of datetime module has several attributes belonging to the following categories:
Time
Time zone
Daylight Saving Clock Adjustments
time - class attributes
time.min
- Provides the minimum time that can be represented. - The minimum time that can be represented is zero hours, zero minutes, zero seconds and zero microseconds. - The minimum time is the first microsecond of a day.
time.max
- Provides the maximum time that can be represented. - The maximum time that can be represented is 23 hours, 59 minutes, 59 seconds and 99999 microseconds. - The maximum time is the last microsecond of a day.
time.resolution
- Represents the minimum difference between two unequal time objects. - The resolution is 1 microsecond.
time - instance attributes
hour
- Represents the number of hours in a time quantity. - Minimum hour is zero, which corresponds to 0 hours midnight or 12 AM. - Maximum hour is 23, which corresponds 11PM.
minutes
- Represents the number of minutes in a time quantity. - Minimum value is 0 and the maximum value is 59.
seconds
- Represents the number of seconds in a time quantity. - Minimum value is 0 and the maximum value is 59.
microseconds
- Represents the number of microseconds in a time quantity. - Minimum value is 0 and the maximum value is 999999. - A microsecond is one millionth of a second -That is 1/1000000 second or 0.000001 second or 10-6 second.
tzinfo
- An object of a tzinfo derived class. - tzinfo attribute represents the time zone. The datetime module has a timezone concrete class for this purpose.
fold
- The fold attribute represents that whether at least once a fold in time has occurred for this time. - A fold in time occurs when a clock is reversed back to the past time. - If fold is set to 1 it means this time instance is result of a reversal of the clock. - The fold attribute is required to model the event of clock reversal typically for duration of one hour at the end of the summer time or daylight saving time.
Example
python
import datetime
# Create a timezone instance using timedelta
estTimeDelta = datetime.timedelta(hours=-5)
estTZObject = datetime.timezone(estTimeDelta, name="Eastern Standard Time")
# End of DST for 2017 - at 2 AM clock reversed to 1 AM
# So this 1 AM has a fold onto it
dstEndTime = datetime.time(1,0,0,0,tzinfo=estTZObject,fold=1)
#print all the attributes of the time object
print("Hours:{}".format(dstEndTime.hour))
print("Minutes:{}".format(dstEndTime.minute))
print("Seconds:{}".format(dstEndTime.second))
print("MicroSeconds:{}".format(dstEndTime.microsecond))
print("Time zone:{}".format(dstEndTime.tzinfo))
print("Fold:{}".format(dstEndTime.fold))
Output
Output
Hours:1
Minutes:0
Seconds:0
MicroSeconds:0
Time zone:Eastern Standard Time
Fold:1
Your privacy choices
We'd like to use Google Analytics cookies to count visits and see which tutorials are useful.
They are only set if you accept. We don't use advertising cookies and we don't sell your data.
You can change your choice any time from “Your privacy choices” at the bottom of every page.
Privacy Policy
Your privacy choices
Your browser sent a Global Privacy Control signal, so analytics is off unless you turn it on here.
Strictly necessary
Remembers this choice in your browser. No cookies, nothing sent to anyone.Always on