How can I produce a human readable difference when subtracting two UNIX timestamps using Python?

后端 未结 7 1024
無奈伤痛
無奈伤痛 2020-12-23 19:39

This question is similar to this question about subtracting dates with Python, but not identical. I\'m not dealing with strings, I have to figure out the difference between

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 20:08

    Check out the humanize package

    https://github.com/jmoiron/humanize

    import datetime
    
    humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=1))
    
    'a second ago'
    
    humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=3600))
    
    'an hour ago'
    

提交回复
热议问题