stftimeと、strptimの違いについてメモ
(1)前提
datetimeモジュールのdatetiemクラスをインポートして、today()関数の結果を変数tに代入
from datetime import datetime
t = datetime.today
t
とすると、
datetime.datetime(2020, 3, 12, 23, 37, 45, 238787)
となる
(2)datetime型 → str型
str_t = t.strftime('%Y年%m月%d日/%H時%M分%S秒')
str_t
とすると、
'2020年03月12日/23時37分45秒'
となる
(3)str型 → datetime型
time_t = datetime.strptime(str_t, '%Y年%m月%d日/%H時%M分%S秒')
time_t
とすると、
datetime.datetime(2020, 3, 12, 23, 37, 45)
となる。