Language: Python
Date & Time
Arrow was created by Chris Smith to address the limitations of Python's standard `datetime` module. It focuses on simplicity, readability, and human-friendly operations, enabling developers to handle date and time in an intuitive manner.
Arrow is a Python library that provides a sensible, human-friendly approach to creating, manipulating, formatting, and converting dates and times. It simplifies working with time zones and datetime arithmetic.
pip install arrowconda install -c conda-forge arrowArrow allows you to create datetime objects, shift them by time intervals, convert between time zones, format and parse strings, and perform human-readable operations.
import arrow
now = arrow.now()
print(now)Retrieves the current local time as an Arrow object.
import arrow
dt = arrow.get('2025-08-21 15:30', 'YYYY-MM-DD HH:mm')
print(dt)Parses a string to create a specific datetime using a format string.
import arrow
now = arrow.now()
future = now.shift(days=+5, hours=+3)
print(future)Shifts the datetime forward by 5 days and 3 hours.
import arrow
now = arrow.now('UTC')
ny = now.to('America/New_York')
print(ny)Converts a UTC datetime to another timezone, e.g., New York.
import arrow
now = arrow.now()
print(now.format('YYYY-MM-DD HH:mm:ss'))Formats the Arrow object into a human-readable string.
import arrow
past = arrow.get('2025-08-01')
now = arrow.now()
print(past.humanize(now))Shows the difference between two datetimes in a human-friendly way, e.g., '3 weeks ago'.
import arrow
dt = arrow.get('21/08/2025', 'DD/MM/YYYY')
print(dt.format('YYYY-MM-DD'))Parses a date string with a custom format and converts it into another format.
Use Arrow objects instead of Python datetime objects for simplicity and readability.
Always specify a timezone when working with global applications.
Use humanize for user-friendly time displays.
Prefer `shift()` over manual datetime arithmetic.
Use Arrow for parsing, formatting, and conversion to reduce boilerplate code.