箭头日期时间

人性化的时间格式和转换。

在编辑器中尝试

概述

为标准 python 日期时间解析提供智能包装器。

允许大量简化的转换和人类可读的字符串格式。

代码和执行输出

解析复杂的字符串并推断本地 UTC 变体。

import arrow

# Current UTC time
now = arrow.utcnow()
print(f"Now (UTC): {now.format('YYYY-MM-DD HH:mm:ss')}")

# Shift time forward
future = now.shift(days=14, hours=6)
print(f"Release date: {future.humanize()}")
print(f"Exact date:   {future.format('dddd, MMMM Do YYYY')}")

# Parse chaotic string
parsed = arrow.get("2025-07-04T12:00:00-04:00")
print(f"\nParsed US/Eastern: {parsed}")

# Convert across timezones
import pytz
zones = ['Asia/Tokyo', 'Europe/London', 'America/New_York']
print("\nFuture Date around the world:")
for tz_name in zones:
    tz = pytz.timezone(tz_name)
    local_dt = future.datetime.astimezone(tz)
    print(f"  {tz_name:<25} {local_dt.strftime('%Y-%m-%d %H:%M %Z')}")
端子输出
Now (UTC): 2025-XX-XX XX:XX:XX
Release date: in 14 days
Exact date:   ...

逐步实施

  • 时区转换
  • CRON日志评估
  • 数据库时间戳突变

常见问题解答

相关主题