脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python将秒数转化为时间格式的实例

python将秒数转化为时间格式的实例

2021-04-02 00:28爱数星星的孩子 Python

今天小编就为大家分享一篇python将秒数转化为时间格式的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

1、转化时间格式

?
1
2
3
4
seconds =35400
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print("%d:%02d:%02d" % (h, m, s))

结果:9:50:00

2、转化成日期时间格式

?
1
2
3
4
import time
timeArray = time.localtime(1462482700)#秒数
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print(otherStyleTime)

结果:2016-05-06 05:11:40

以上这篇python将秒数转化为时间格式的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/xiaoQL520/article/details/78435175

延伸 · 阅读

精彩推荐