推 a08054491: 這個好方便 11/02 12:24
※ 引述《gigigigi (gigigigi)》之銘言:
: 我爬資料網站文章時間格式如下
: Thu Oct 25 23:36:17 2018
: 那我需要比對每篇文章相差幾分鐘
: 想請問一下有方法可以把上面時間格式轉成分鐘後我在相減
: 謝謝
處理時間格式可以考慮用 arrow 這個 package:
https://arrow.readthedocs.io/en/latest/
--
以你的例子來說:
import arrow
time1 = "Thu Oct 25 23:36:17 2018"
time2 = "Thu Oct 25 23:45:16 2019"
# Get Regular Time Format
time1 = arrow.get(time1, 'MMM DD HH:mm:ss YYYY')
time2 = arrow.get(time2, 'MMM DD HH:mm:ss YYYY')
# Get Difference between time1 and time2
diff = time2 - time1
print(diff.days*1440 + diff.seconds/60)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 148.177.185.133
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1540519718.A.3A6.html