O'Reilly logo

Automate it! - Recipes to upskill your business by Chetan Giridhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with time, date, and calendar

In this recipe, we will use built in Python modules and we don't need to install anything explicitly. So let's get started.

How to do it...

  1. Go to your favorite editor, create a file named 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:

  2. Python's Time class has ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required