In this recipe, we will use built in Python modules and we don't need to install anything explicitly. So let's get started.
time_ex.py, and write the following code in the Python file:
import datetime time_obj = datetime.time(13, 2, 23) print "Time object is:", time_obj print 'Hour :', time_obj.hour print 'Minute:', time_obj.minute print 'Second:', time_obj.second print 'Microsecond:', time_obj.microsecond
If we run the preceding Python code, we will see the following output. Observe how we created a given time object using Python and retrieved the hour, minute, second, and microsecond details for the given time object:
Timeclass has ...