Skip to main content

A very simple python lib, used to format datetime with *** time ago statement. Javascript version here. timeago.js.

Build Status PyPi Status Python Versions

Such as:

just now
12 seconds ago
3 minutes ago
2 hours ago
24 days ago
6 months ago
2 years ago

in 12 seconds
in 3 minutes
in 2 hours
in 24 days
in 6 months
in 2 years

For other languages see below.

Install

pip install timeago

Usage & Example

# -*- coding: utf-8 -*-
import timeago, datetime

now = datetime.datetime.now() + datetime.timedelta(seconds = 60 * 3.4)

date = datetime.datetime.now()

# locale
print (timeago.format(date, now, 'zh_CN')) # will print `3分钟前`

# input datetime
print (timeago.format(date, now)) # will print 3 minutes ago

# input timedelta
print (timeago.format(datetime.timedelta(seconds = 60 * 3.4))) # will print 3 minutes ago

# input date, auto add time(0, 0, 0)
print (timeago.format(datetime.date(2016, 5, 27), now))

# input datetime formatted string
print (timeago.format('2016-05-27 12:12:03', '2016-05-27 12:12:12')) # will print just now

# inverse two parameters
print (timeago.format('2016-05-27 12:12:12', '2016-05-27 12:12:03')) # will print a while

Method & Parameter

only one API format.

Three parameters of method format:

  • date: the parameter which will be formatted, must be instance of datetime / timedelta or datetime formatted string.

  • now: reference time, must be instance of datetime or datetime formatted string.

  • locale: the locale code, default en.

Locale

At the time we’re speaking, following locale are available:

  • ar

  • bg

  • ca

  • da

  • de

  • el

  • en

  • en_short

  • es

  • eu

  • fa_IR

  • fi

  • fr

  • gl

  • guj_IN

  • he

  • hu

  • in_BG

  • in_HI

  • in_ID

  • is

  • it

  • ja

  • ko

  • lt

  • ml

  • my

  • nb_NO

  • nl

  • nn_NO

  • pl

  • pt_PT

  • pt_BR

  • ro

  • ru

  • sk

  • sv_SE

  • ta

  • th

  • tr

  • uk

  • vi

  • zh_CN

  • zh_TW

Localization

  1. Fork the project

  2. Create a locale python script called [name_of_your_locale].py following the existing other locales.

  3. Add the name of your locale in the Readme to keep it updated (alphabetically).

  4. Add test case following the english model

  5. Create the Pull Request.

Notes

For complicated plurals, you can take example on the PL (Polish) locale here

Release files for timeago 1.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for timeago 1.0.16
File Interpreter ABI Platform
timeago-1.0.16-py3-none-any.whl Python 3 none any Details

Release files / timeago-1.0.16-py3-none-any.whl

Download URL timeago-1.0.16-py3-none-any.whl
Size 29.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b8cb2e3102b329f35a04aa4531982d867b093b19481cfbb1dac7845fa2f79b0
BLAKE2b-256 checksum
How to use checksums
5f888dac5496354650972434966ba570a4a824fafed43471cf190faea4b085fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.0.16 This release

1 release file

1.0.15

1 release file

1.0.14

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

2 release files

1.0.9

2 release files

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page