Arrow: Better Dates & Times for Python

1.4.0 · active · verified Sat Mar 28

Arrow is a Python library that offers a sensible, human-friendly approach to dates, times, and timestamps. It aims to be a drop-in replacement for the `datetime` module, providing a more convenient API for creating, manipulating, formatting, and converting dates and times, including robust timezone handling and humanization. The current version is 1.4.0, and it maintains an active release cadence, with updates typically occurring every few months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to get current times, parse date strings, format Arrow objects, perform time shifts, and humanize time differences.

import arrow

# Get current UTC time
now_utc = arrow.utcnow()
print(f"Current UTC: {now_utc}")

# Get current local time
now_local = arrow.now()
print(f"Current Local: {now_local}")

# Parse a string into an Arrow object
dt_string = '2023-10-27T10:30:00-05:00'
dt_obj = arrow.get(dt_string)
print(f"Parsed datetime: {dt_obj}")

# Format an Arrow object
formatted_dt = dt_obj.format('YYYY-MM-DD HH:mm:ss ZZ')
print(f"Formatted datetime: {formatted_dt}")

# Shift an Arrow object
tomorrow = now_local.shift(days=+1)
yesterday = now_local.shift(days=-1)
print(f"Tomorrow: {tomorrow}")
print(f"Yesterday: {yesterday}")

# Humanize an Arrow object
humanized_diff = tomorrow.humanize(now_local)
print(f"Tomorrow relative to now: {humanized_diff}")

view raw JSON →