WEB 1.1 - Module 4: Lesson 3

Learning Outcomes 💫

By the end of this lesson, you should be able to...

Videos 🎥

Vid 1 - using datetime objects

Vid 1 - using datetime objects

Exercises 💪

Complete the exercise in this repl.it and submit your work.

Written Companion 🗒

<aside> 🤔 How can we easily create objects that represent specific times and dates in a universally accepted format?

</aside>


Python has a built-in library called datetime. This library provides developers access to the datetime object—an object containing date and time in a common format.

A datetime object can easily be created using the datetime.now() method and assigning it to a variable.

# creating a new datetime object in python
from datetime import datetime

datetime_obj = datetime.now()

print(datetime_obj)
# 2020-09-02 21:17:19.511047