i want to convert from epoch to date like that : 1575135888 ==> 3 years ago (https://i.stack.imgur.com/x2ZPW.png)
i have this code :
date_c = datetime.datetime.fromtimestamp(1575135888)
print(datetime.date.today())
print(date_c)
i got 2022-12-09
and 2019-11-30 18:44:48
i don't know how to cenvert it to 3 years ago
CodePudding user response:
Well, you could use timedelta like this:
from datetime import datetime
print(datetime.today() - datetime.fromtimestamp(1575135888), "ago")
Output:
1104 days, 15:57:21.760720 ago
But I'm afraid that the meaning of "years ago" is ambiguous: Does it mean 365 days, 365.25 days?