datetime ライブラリを使う
ここでは datetime ライブラリ、特に文字列の日付を「日・月・年」を特定して特定の文字列フォーマットに変換する datetime.strptime(date_string, format) メソッドを使います。以下の表を参考に、次の各日付から年・月・日を正しく読み取るためのコードを決めてください(コンソールでメソッドを出力して答えを確認できます):
- 12-01-1990(米国形式 m-d-y)
- 23/08/2020(EU 形式 d-m-y)
| Directive | Meaning | Example |
|---|---|---|
| %d | Day of the month as a zero-padded decimal number | 01, 02, …, 31 |
| %b | Month as locale’s abbreviated name | Jan, Feb, …, Dec |
| %B | Month as locale’s full name | January, …, December |
| %m | Month as a zero-padded decimal number | 01, 02, …, 12 |
| %y | Year without century as a zero-padded decimal number | 00, 01, …, 99 |
| %Y | Year with century as a decimal number | 1970, 1988, 2001, 2013 |
この演習はコースの一部です
