User-friendly time format in Python?

后端 未结 14 1490
[愿得一人]
[愿得一人] 2020-12-12 10:06

Python: I need to show file modification times in the \"1 day ago\", \"two hours ago\", format.

Is there something ready to do that? It should be in English.

14条回答
  •  北海茫月
    2020-12-12 10:51

    This is the gist of @sunil 's post

    >>> from datetime import datetime
    >>> from dateutil.relativedelta import relativedelta
    >>> then = datetime(2003, 9, 17, 20, 54, 47, 282310)
    >>> relativedelta(then, datetime.now())
    relativedelta(years=-11, months=-3, days=-9, hours=-18, minutes=-17, seconds=-8, microseconds=+912664)
    

提交回复
热议问题