Turning strings into datetimes
When you download data from the Internet, dates and times usually come to you as strings. Often the first step is to turn those strings into datetime
objects.
In this exercise, you will practice this transformation.
Reference | |
---|---|
%Y | 4 digit year (0000-9999) |
%m | 2 digit month (1-12) |
%d | 2 digit day (1-31) |
%H | 2 digit hour (0-23) |
%M | 2 digit minute (0-59) |
%S | 2 digit second (0-59) |
Diese Übung ist Teil des Kurses
Working with Dates and Times in Python
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Import the datetime class
from datetime import datetime
# Starting string, in YYYY-MM-DD HH:MM:SS format
s = '2017-02-03 00:00:01'
# Write a format string to parse s
fmt = '____'
# Create a datetime object d
d = datetime.____(____, ____)
# Print d
print(d)