datetime:打印为秒 [英] datetime: print as seconds

查看:106
本文介绍了datetime:打印为秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 datetime 对象。我想打印它只是几秒钟(即1分30.5秒打印为90.5秒)。似乎没有找到一种方式来实现 strftime

I have a datetime object. I want to print it as just number of seconds (i.e., 1 min 30.5 sec should print as 90.5 s). Can't seem to find a way to do it with strftime.

推荐答案

p>我认为,对于你的情况,你最好使用datetime.timedelta对象。它有一个功能,将完成你想要的,datetime.timedelta.total_seconds()。

I think that for your situation you'd be better off using a datetime.timedelta object. It has a function that will do exactly what you want, datetime.timedelta.total_seconds().

这篇关于datetime:打印为秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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