python如何计算时间差


本文摘自php中文网,作者coldplay.xixi,侵删。

python计算时间差的方法:python求时间差主要是用的datetime包,包括同一天情形下的时间差和不同天情形下的时间差,语法为【from datetime import datetime, date】。

本教程操作环境:windows7系统、python3.9版,DELL G3电脑。

python计算时间差的方法:

python求时间差主要是用的datetime包,包括同一天情形下的时间差和不同天情形下的时间差。

1

from datetime import datetime, date

1、同一天情形下的时间差(秒)seconds ,分钟由秒数除以60即可

1

2

3

4

5

6

7

8

9

#计算时间差的分钟数

# 同一天的时间差

time_1 = '2020-03-02 15:00:00'

time_2 = '2020-03-02 16:00:00'

time_1_struct = datetime.strptime(time_1, "%Y-%m-%d %H:%M:%S")

time_2_struct = datetime.strptime(time_2, "%Y-%m-%d %H:%M:%S")

seconds = (time_2_struct - time_1_struct).seconds

print('同一天的秒数为:')

print(seconds)

阅读剩余部分

相关阅读 >>

Python的numpy中常用函数的详细介绍

Python实现有序字典方法示例

Python的注释符是什么

能够编译运行Python的软件有哪些

9种Python web程序的部署方式小结

Python中__call__ 方法的使用介绍(附示例)

调试设置中的Python路径无效怎么办

Python 如何自定义模块?

总结关于Python中的中文编码问题

Python取余运算符是什么?

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...