All Python Tutorial Links

How to get current time in Python?

Current Time in Python

Hello Programmers!
In this tutorial, I will teach you how to get the current time in python. This is an advanced topic of python. If you have any questions then you can comment below. So, let's get started.

Example-1: Current Time using Python:

from datetime import datetime

now = datetime.now()

print("Current Time =", now)



Output:

Current Time = 2020-12-30 16:47:25.472735


In the above code, we have imported datetime class from datetime module. Then we have used now() method to get the current time.


Example-2: Current Time (only time)

from datetime import datetime

now = datetime.now()

current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)

Output:

Current Time = 16:51:45


By running the above code you can see the current time only.

Congratulations! Now you know how to print current time using python. This was a very advanced concept of python. If you have any questions then you can comment below. 

Get current date in Python --> https://pythonproramming.blogspot.com/2020/12/how-to-get-current-date-in-python.html

Happy Coding :)

current date and time in python,time,how to get current time in python,how to get current date & time in python?,display current date and time in python

Comments