處理格式: 西歷
2016-11-11 18:28:26
2016- 11-11 18:28:54
from datetime import datetime, timedelta
with open('data', 'r') as f:
datetimes = [datetime.strptime(line.strip(), "%Y-%m-%d %H:%M:%S") for line in f]
def get_dhms(td):
"""
given a timedelta then return corresponding days/hours/minutes/seconds
"""
seconds = td.total_seconds()
# return seconds/86400, seconds/3600, seconds/60, seconds # 如果不捨去小數點,用此行
return seconds//86400, seconds//3600, seconds//60, seconds
for dt in datetimes[1:]:
td = (dt - datetimes[0])
print dt, 'vs', datetimes[0], '->', get_dhms(td)
處理格式: 西歷
2016-11-11 18:28:26
NOV-11-2016 18:28:26
(目前還沒有找到解法)
處理格式: 民國
105-11-11 18:28:26
105-11-11 18:28:29
(目前還沒有找到解法)