Python Get the Current Time

Python logo

In Python, time are not a data type of its own, but a module named time can be imported to work with the time. There are a number of ways you can get current time in Python, but in this tutorial we just import the time module to get the current time. I also recommend checking out the datetime module. Maybe we’ll do a more extensive article on that module as well.

Example 1: Current time using time module

First we need to import date module:

import time

Then we call the function Print to print the current time.


Then we get the current datetime:


Fri May 21 20:40:20 2021

Example 2: Current time using time module

We can get only current time too:

import time

 t = time.localtime()
 current_time = time.strftime("%H:%M:%S", t)




This article explains the use of time module to get the current time with two simple examples.

If you like this blog post and it was useful to you, please follow us on Twitter and Facebook.

Related articles


Post a Comment