Timeago (Python)

1.0.16 · active · verified Sun Apr 12

A very simple Python library, used to format datetime with a "*** time ago" statement, e.g., "3 hours ago". The current version is 1.0.16. The project has a slower release cadence, with the last release in August 2022, but it is actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core `timeago.format()` function with `datetime.datetime` objects and `datetime.timedelta`. It also shows how to specify a different locale.

import timeago
import datetime

# Get current time for comparison
now = datetime.datetime.now()

# Example 1: Past datetime
past_date = datetime.datetime.now() - datetime.timedelta(days=2, hours=3, minutes=30)
print(f"Past date: {timeago.format(past_date, now)}")

# Example 2: Future datetime (relative to now)
future_date = datetime.datetime.now() + datetime.timedelta(hours=5)
print(f"Future date: {timeago.format(future_date, now)}")

# Example 3: Using a timedelta directly
time_delta_example = datetime.timedelta(seconds=60 * 3.4)
print(f"Timedelta: {timeago.format(time_delta_example)}")

# Example 4: With a specific locale (e.g., Chinese Simplified)
# Ensure your system supports UTF-8 for printing non-ASCII characters
print(f"Locale example (zh_CN): {timeago.format(past_date, now, 'zh_CN')}")

view raw JSON →