Python Get Current Date And Time Example
Hello Friends,
Now let's see example of how to get current datetime in python. I am going to show you python get current date and time. We will learn get current datetime in python.
The datetime module is supplies classes for manipulating dates and times. This article will give you example of get current datetime in python.
Here I will give three example for how to get current datetime in python. I am use datetime and time module to get current current date time. So let's see the below example:
Example 1
example1.py
# import datetime module
from datetime import datetime
currentTimeDate = datetime.now()
print(currentTimeDate)
Run Example
python example1.py
Output:
2021-12-14 16:25:25.425925
Example 2
example2.py
# import datetime module
from datetime import datetime
currentTimeDate = datetime.now()
currentTimeDate = currentTimeDate.strftime("%d/%m/%Y %H:%M:%S")
print(currentTimeDate)
Run Example
python example2.py
Output:
14/12/2021 16:26:06
Example 3
example3.py
# import datetime module
import datetime
# import pytz module for timezone()
import pytz
current_time = datetime.datetime.now(pytz.timezone('Asia/Kolkata'))
print(current_time)
Run Example
python example3.py
Output:
2021-12-14 16:26:52.295001+05:30
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?