Getting the Current Date and Time
To retrieve the current date and time, we can use a function called datetime.now()
to get that information.
In a later course, you'll learn all aboutfunctions. For now, just know thatdatetime.now()
calls on a piece of code that comes with Python that figures out the current date and time for us.
from datetime import datetime
now=datetime.now()
print now
-
Create a variable called
now
and store the result ofdatetime.now()
in it. We'll use this variable in the next exercise. -
Go ahead and print the value of the variable
now
.