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 |
|
time.max |
|
time.resolution |
|
time - instance attributes |
|
hour |
|
minutes |
|
seconds |
|
microseconds |
|
tzinfo |
|
fold |
|
Example:
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:
Hours:1 Minutes:0 Seconds:0 MicroSeconds:0 Time zone:Eastern Standard Time Fold:1 |