写上篇日志时 偶然发现这个 可以输出可读性很好的日期格式

http://pypi.python.org/pypi/py-pretty/1

Formats dates, numbers, etc. in a pretty, human readable format.

Downloads ↓

Sample code::

from datetime import datetime, timedelta
now = datetime.now()
hrago = now - timedelta(hours=1)
yesterday = now - timedelta(days=1)
tomorrow = now + timedelta(days=1)
dayafter = now + timedelta(days=2)

import pretty
print pretty.date(now)                      # 'now'
print pretty.date(hrago)                    # 'an hour ago'
print pretty.date(hrago, short=True)        # '1h ago'
print pretty.date(hrago, asdays=True)       # 'today'
print pretty.date(yesterday, short=True)    # 'yest'
print pretty.date(tomorrow)                 # 'tomorrow'
应该会用得到的
收藏起来

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-10-28
  • 2022-02-10
  • 2021-10-26
  • 2021-04-16
  • 2022-12-23
猜你喜欢
  • 2021-09-02
  • 2021-06-16
  • 2022-02-24
  • 2022-02-18
  • 2021-07-24
  • 2021-09-23
  • 2021-12-17
相关资源
相似解决方案