By the end of this lesson, you should be able to...
strftime()
library function to format datetime objects using a custom format.strptime()
library function to parse strings containing dates and times and turn them into datetime objects.Vid 1 - using datetime
objects
Vid 1 - using datetime
objects
Complete the exercise in this repl.it and submit your work.
<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