我最近偶然发现了这个很棒的 pendulum
" dateTimes"使"简单"库。
它具有显示"类似人"差异的非常好的功能:
In [1]: import pendulum
In [2]: now = pendulum.now()
In [3]: future = now.add(years=10)
In [4]: future.diff_for_humans()
Out[4]: '10 years from now'
但是,是否有可能使其在更复杂的差异中起作用 - 例如"年"one_answers"周"?
In [5]: future = now.add(years=10, weeks=5)
In [6]: future.diff_for_humans()
Out[6]: '10 years from now'
我希望它输出10 years and 5 weeks from now
。
来自Pendulum Module Readme:
now = pendulum.now()
future = now.add(years=10, weeks=5)
delta = future - now
delta.in_words()
>>>'10 years 1 month 4 days'
https://github.com/sdispater/pendulum