Python Program To Get Current Time
Sep 16, 2021
Hi Guys,
In this blog, I will show how to get get current time in python. We will talk about get current time using python program. In this article, we will know how to get the current time in Python.
This article will give you example of get current time using pytz module in python. I am going to learn you python get current time example.
Here i will give you three example of how to get current time in python. So let's see bellow example:
Example 1
from datetime import *
import pytz
tz = pytz.timezone('Asia/Kolkata')
datetime = datetime.now(tz)
print("INDIA time:", datetime.strftime("%H:%M:%S"))
Output:
INDIA time: 04:58:06
Example 2
from datetime import datetime
# now() method is used to
# current date & time object.
nowDateTime = datetime.now()
# strftime() method used to
# get current time.
currentTime = nowDateTime.strftime("%H:%M:%S")
print("Current Time =", currentTime)
Output:
Current Time = 04:58:06
Example 3
from datetime import datetime
# Time object containing
time = datetime.now().time()
print("Current Time is ", time)
Output:
Current Time is 04:58:06
It will help you....
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?