- Notifications
You must be signed in to change notification settings - Fork37
⌛ Simple library used to format datetime with `*** time ago` statement. eg: "3 hours ago".
License
NotificationsYou must be signed in to change notification settings
hustcc/timeago
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A very simple python lib, used to format datetime with*** time ago
statement. Javascript version here.timeago.js.
Such as:
just now12 seconds ago3 minutes ago2 hours ago24 days ago6 months ago2 years agoin 12 secondsin 3 minutesin 2 hoursin 24 daysin 6 monthsin 2 years
For other languages see below.
pip install timeago
# -*- coding: utf-8 -*-importtimeago,datetimenow=datetime.datetime.now()+datetime.timedelta(seconds=60*3.4)date=datetime.datetime.now()# localeprint (timeago.format(date,now,'zh_CN'))# will print `3分钟前`# input datetimeprint (timeago.format(date,now))# will print 3 minutes ago# input timedeltaprint (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 stringprint (timeago.format('2016-05-27 12:12:03','2016-05-27 12:12:12'))# will print just now# inverse two parametersprint (timeago.format('2016-05-27 12:12:12','2016-05-27 12:12:03'))# will print a while
only one APIformat
.
Three parameters of methodformat
:
date
: the parameter which will be formatted, must be instance ofdatetime
/timedelta
or datetime formatted string.now
: reference time, must be instance ofdatetime
or datetime formatted string.locale
: the locale code, defaulten
.
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_BR
pt_PT
ro
ru
sk
sv_SE
ta
th
tr
uk
vi
zh_CN
zh_TW
- Fork the project
- Create a locale python script called
[name_of_your_locale].py
following the existing other locales. - Add the name of your locale in the Readme (both in MD and in RST) to keep it updated (alphabetically).
- Add test case following theenglish model
- Create the Pull Request.
For complicated plurals, you can take example on the PL :flag-pl: localehere
About
⌛ Simple library used to format datetime with `*** time ago` statement. eg: "3 hours ago".
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published