Method Name:
timetz
Method Signature:
timetz()
Method Overview:
- The timetz() instance method of the python datetime class returns a time object.
- The returned time object will have only the time information of the datetime class as its attributes.
- The returned object is an “aware” object, if the original object has the tzinfo set.
Example:
import datetime
# Create a timedelta with the number of hours CST is behind UTC cstTimeDelta = datetime.timedelta(hours=-6)
# Create a timezone instance for CST tzObject = datetime.timezone(cstTimeDelta, name="CST")
# Create exactly when June ends/half of the year datetimeObject = datetime.datetime(2017,6,30,23,59,59,99,tzObject)
# Retrieve time instance embedded with a timezone object from the original datetime awareObject = datetimeObject.timetz()
# Print the datetime object print(datetimeObject)
# Print the time object print(awareObject)
# Print the timezone information from time print(awareObject.tzinfo)
|
Output:
2017-06-30 23:59:59.000099-06:00 23:59:59.000099-06:00 CST |