Python中的日期差异(以分钟为单位) [英] Date difference in minutes in Python

查看:93
本文介绍了Python中的日期差异(以分钟为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算Python中以下时间戳记的时间差(分钟)?

How do I calculate the difference in time in minutes for the following timestamp in Python?

2010-01-01 17:31:22
2010-01-03 17:31:22


推荐答案

from datetime import datetime

fmt = '%Y-%m-%d %H:%M:%S'
d1 = datetime.strptime('2010-01-01 17:31:22', fmt)
d2 = datetime.strptime('2010-01-03 17:31:22', fmt)

print (d2-d1).days * 24 * 60

这篇关于Python中的日期差异(以分钟为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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