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 convert it to 3 years ago.
Advertisement
Answer
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?