2017-06-28 8 views
2

私はcsvからpythonに日付を2017-01-04の形式で読み込んでいます。Pythonの時刻データフォーマット

time data '2017-01-04' does not match format '%y-%m-%d'

それは何をする必要があります:私は、データを処理するとき、私はエラーを取得する私はしかしdate_format = "%y-%m-%d"

を使用

from datetime import datetime  
day1 = datetime.strptime(date1, date_format) 

、などの日付を処理しようとしていますか?

+3

''%Y-%m-%d "'大文字 ' Y 'を4桁の年に渡す場合は、[docs](https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior) – EdChum

答えて

0

何かのように:そのため

from datetime import datetime 
day1 = datetime.utcnow().strptime('2017-01-04', '%Y-%m-%d') 
4

Y - Year with century as a decimal number.

y - Year without century as a zero-padded decimal number.

、あなたはhere

0

You can run it-This code run successfully and print-2017-01-04 00:00:00

 from datetime import datetime 
    day1 = datetime.utcnow().strptime('2017-01-04', '%Y-%m-%d') 
    print(day1) 
でそれをすべて見ることができ、フォーマットの詳細についてはアッパーY.

を使用する必要があります

関連する問題