Python time to age

后端 未结 6 2406
野的像风
野的像风 2020-12-20 03:23

I\'m trying to convert a date string into an age.

The string is like: \"Mon, 17 Nov 2008 01:45:32 +0200\" and I need to work out how many days old it is.

I h

6条回答
  •  [愿得一人]
    2020-12-20 03:50

    In Python, datetime objects natively support subtraction:

    from datetime import datetime
    age = datetime.now() - datetime.strptime(...)
    print age.days
    

    The result is a timedelta object.

提交回复
热议问题