All Courses

How to use datetime objects?

By Rama, 2 years ago
  • Bookmark
0

How to use date, time, and datetime object?

Datetime
1 Answer
0

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

Your Answer

Webinars

Why You Should Learn Data Science in 2023?

Jun 8th (7:00 PM) 289 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More