爱意满满的作品展示区。
50vip

刚撸的一个 python 库 timeago

  •  
  •   50vip · May 26, 2016 · 2582 views
    This topic created in 3663 days ago, the information mentioned may be changed or developed.

    看名字应该就知道是什么意思了,就是将时间转化成多少多少时间之前。很多网站都会用到的。

    github 地址:https://github.com/hustcc/timeago 下面直接是 readme 内容。

    发布到 pipy 了,直接 pip install timeago 即可体验。

    timeago

    A python lib format datetime to *** time ago.

    Build Status PyPi Status Python Versions PyPi Downloads

    Install

    pip install timeago
    

    Usage & Example

    import timeago, datetime
    
    now = datetime.datetime.now() + datetime.timedelta(seconds = 60 * 3.4)
    
    print (timeago.format(date, now)) # will print 3 minutes ago
    

    Methor & Parameter

    only one API format.

    Three parameters of method format:

    • date: datetime will be done / format.
    • now: reference time, must be instance of datetime.
    • locale: the locale code, only zh_CN / en supported, default en.

    Localization

    1. foke the project
    2. add <locale>.py file in the locales folder.
    3. pull a request.
    gogobody
        1
    gogobody  
       May 27, 2016 via Android   ❤️ 1
    支持~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3025 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 06:09 · PVG 14:09 · LAX 23:09 · JFK 02:09
    ♥ Do have faith in what you're doing.