arrow

Utilities

人類友善的日期

概述 arrow

Arrow 是一個 Python 函式庫,它提供了一種人性化的方法來建立、操作、格式化和轉換日期和時間。它可以作為日期時間的直接替代品,具有更簡單的 API、預設時區感知以及直覺的時間平移方法,例如 .shift(days=-1) 和 . humanize()。

在PyRun中,Arrow 可透過 micropip 取得。您可以探索日期算術、時區轉換、相對時間格式和日期解析,而無需費力地瀏覽 Python 的標準日期時間樣板 — 全部在瀏覽器中完成,無需任何設定。

程式碼和執行輸出

人性化的時區轉換和時間平移。

Arrow Date & Time在編輯器中執行
import arrow

now = arrow.now()
print("Now (local):", now.format("YYYY-MM-DD HH:mm:ss ZZ"))
print("Now (UTC)  :", now.to("UTC").format("YYYY-MM-DD HH:mm:ss"))

past = now.shift(days=-10, hours=-3)
print("\n10 days 3 hrs ago:", past.humanize())

dt = arrow.get("2025-07-04 12:00:00", "YYYY-MM-DD HH:mm:ss", tzinfo="US/Eastern")
print("\nNew York :", dt.format("YYYY-MM-DD HH:mm ZZ"))
print("Tokyo    :", dt.to("Asia/Tokyo").format("YYYY-MM-DD HH:mm ZZ"))
print("Mumbai   :", dt.to("Asia/Kolkata").format("YYYY-MM-DD HH:mm ZZ"))

相關套餐

推薦的 Python 資源

透過相關的互動式教學、備忘單和程式碼比較來擴展您的知識。