World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
The datetime module contains three primary types of objects - date, time, and datetime.
import datetime # Date object today = datetime.date.today() print("Today : ",today) new_year = datetime.date(2020, 12, 10) #datetime.date(2020, 12, 10) print("Date : ",new_year) # Time object noon = datetime.time(12, 0, 0) #datetime.time(12, 0) print("Time : ",noon) # Current datetime now = datetime.datetime.now() print("Current Date Time: ",now)
Output :
Today : 2021-04-21 Date : 2020-12-12 Time : 12:00:00 Current Date Time: 2021-04-21 06:26:03.498089