Python的timedelta:我不能在任何时间单位得到我想要的全部差异的价值? [英] Python's timedelta: can't I just get in whatever time unit I want the value of the entire difference?

查看:93
本文介绍了Python的timedelta:我不能在任何时间单位得到我想要的全部差异的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我的网站上发布了一个帖子以来,我试图找到一些聪明的日期(从...开始的时间,从...之后的几个小时),我使用的是datetime.timedelta utcnow和utc之间的区别存储在数据库中的一篇文章。



根据文档,我必须使用days属性AND秒属性来获取花哨的日期字符串想。



我不能在任何时间单位得到整个差异的价值?我错过了什么吗?



如果我能够在几秒钟内获得整体差异,这将是完美的。

解决方案

似乎Python 2.7引入了一个 total_seconds()方法,这是你正在寻找的,我相信!


I am trying to have some clever dates since a post has been made on my site ("seconds since, hours since, weeks since, etc..") and I'm using datetime.timedelta difference between utcnow and utc dated stored in the database for a post.

Looks like, according to the docs, I have to use the days attribute AND the seconds attribute, to get the fancy date strings I want.

Can't I just get in whatever time unit I want the value of the entire difference? Am I missing something?

It would be perfect if I could just get the entire difference in seconds.

解决方案

It seems that Python 2.7 has introduced a total_seconds() method, which is what you were looking for, I believe!

这篇关于Python的timedelta:我不能在任何时间单位得到我想要的全部差异的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆