MulaiMulai sekarang secara gratis

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
%Y4 digit year (0000-9999)
%m2 digit month (1-12)
%d2 digit day (1-31)
%H2 digit hour (0-23)
%M2 digit minute (0-59)
%S2 digit second (0-59)

Latihan ini adalah bagian dari kursus

Working with Dates and Times in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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)
Edit dan Jalankan Kode