V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
50vip
V2EX  ›  分享创造

刚撸的一个 python 库 timeago

  •  
  •   50vip · 2016-05-26 13:23:26 +08:00 · 2011 次点击
    这是一个创建于 2905 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    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  
       2016-05-27 16:00:20 +08:00 via Android   ❤️ 1
    支持~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1032 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:06 · PVG 06:06 · LAX 15:06 · JFK 18:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.