Re: [問題] 時間格式轉換問題

看板Python作者 (馬士登)時間6年前 (2018/10/26 10:08), 編輯推噓1(100)
留言1則, 1人參與, 6年前最新討論串2/3 (看更多)
※ 引述《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

11/02 12:24, 6年前 , 1F
這個好方便
11/02 12:24, 1F
文章代碼(AID): #1RqdScEc (Python)
討論串 (同標題文章)
文章代碼(AID): #1RqdScEc (Python)