Getting Current Year, Month, Day, Time using Python

Python’s built-in module datetime can be used for knowing what is current Year, Month, Day, Time.

Python Code for Getting Current Year

import datetime
current_year = datetime.datetime.now().year
print(current_year)

Python Code for Getting Current Month

import datetime
current_month = datetime.datetime.now().month
print(current_month)

Python Code for Getting Current Day

import datetime
current_day = datetime.datetime.now().day
print(current_day)

Python Code for Getting Current Time

import datetime
current_hour = datetime.datetime.now().hour
current_minute = datetime.datetime.now().minute
current_second = datetime.datetime.now().second
print(str(current_hour) + ":" + str(current_minute) + ":" + str(current_second))
Comments to: Getting Current Year, Month, Day, Time using Python

Your email address will not be published.