[英]Convert epoch to human-readable date python
I want to convert from epoch to date like that: 1575135888 ==> 3 years ago
( https://i.stack.imgur.com/x2ZPW.png )我想像这样从纪元转换为日期:
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
我得到了
2022-12-09
and 2019-11-30 18:44:48
和
2019-11-30 18:44:48
I don't know how to convert it to 3 years ago.我不知道如何将其转换为 3 年前。
Well, you could use timedelta like this:好吧,你可以像这样使用 timedelta:
from datetime import datetime
print(datetime.today() - datetime.fromtimestamp(1575135888), "ago")
Output: 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?但恐怕“几年前”的意思有歧义:是指365天,还是365.25天?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.