LoginSignup
1
1

More than 5 years have passed since last update.

python > datetime > 日付の文字列(ISO format: 2015-12-09 12:40:08)からdatetime型にする

Last updated at Posted at 2015-12-25

2015-12-09 12:40:08というような形式(ISO formatというらしい)からdatetimeへの変換をしたい。

参考 http://qiita.com/shibainurou/items/0b0f8b0233c45fc163cd

以下のように実装した。

from datetime import datetime as dt

strdt1 = "2015-12-09 12:40:08"
strdt2 = "2015-12-09 12:35:08"
tdt1 = dt.strptime(strdt1, "%Y-%m-%d %H:%M:%S")
tdt2 = dt.strptime(strdt2, "%Y-%m-%d %H:%M:%S")

print tdt1
print tdt2

print tdt1 - tdt2
結果
Success time: 0.02 memory: 9184 signal:0
2015-12-09 12:40:08
2015-12-09 12:35:08
0:05:00
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1