人类的日期
human-dates2的Python项目详细描述
这是原包装的叉子 human_dates由乔纳森·图什曼制作,但目前还未修复。在
原来的包基于Stack Overflow answer,引用了另一个 来源(查看帖子)。在
我来自Ruby/Rails世界,我错过了一些约会糖。而不是一直抱怨,我 我想我能做点什么
它提供两套功能:
- 最重要的是它有一个很好的time_ago_in_words函数。在
- 有一些自然的语言来解释事情的开始和结束
注意,我从下面的StackOverflow帖子中窃取了大部分内容:http://stackoverflow.com/a/1551394/192791
注意:当你不给函数传递时间时,它使用日期时间.utcnow()
安装
$ pip install human_dates
timeago\u in_单词用法
^{pr2}$自然语言助手
fromhuman_datesimport*printbeginning_of_day()printbeginning_of_hour()printbeginning_of_year()printend_of_month()# and so on ....# you can also pass a datetime to each of these functionsimporthuman_datesfromdatetimeimportdatetimedate=datetime.strptime('Feb 13 2008 1:33PM','%b %d %Y %I:%M%p')result=human_dates.end_of_month(date)printresult# 2008-02-29 23:59:59.999999
备选方案
- {请看前面的人类日期。它对我来说很重,但对你来说可能很棒)
其他重要的时间库
- 项目
标签: