用Python在Django中将Unix时间戳转换为人类格式

2024-05-16 23:10:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将字符串中的unix时间戳(例如1277722499.82)转换为更人性化的格式(hh:mm:ss或类似格式)。对于django应用程序,在python中有简单的方法可以做到这一点吗?这是一个模板之外,在模型中,我想这样做。谢谢。

编辑 我使用python函数time.time()生成时间戳。据医生说:

time.time()

Return the time as a floating point number expressed in seconds since the epoch, in UTC. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second. While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls.


Tags: the字符串innumbertimeas格式hh