程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

如何在python中转换标准格式的时区并找出差异?[关闭]

发布于2023-08-22 00:09     阅读(1059)     评论(0)     点赞(21)     收藏(4)


我有两个时间 1-> 2023-08-10T10:14:04 和 2-> 2023-08-10T11:38:00 ,我想使用Python找出两个时间之间的差异(以分钟为单位)。

提前致谢!


解决方案


您提供的时间在我看来就像 ISO 标准时间。如果是这样的话,我们可以利用Python标准库的datetime模块来区分差异。

这是我的两分钱

# Import the Python standard datetime module
from datetime import datetime

# Creating the time object for calculations
time1 = datetime.fromisoformat('2023-08-10T10:14:04')
time2 = datetime.fromisoformat('2023-08-10T11:38:00')

# The `total_seconds` will return in a seconds unit, so we need to divide it by 60 to get minutes out of it
diff_in_minutes = (time2 - time1).total_seconds() / 60


所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:https://www.pythonheidong.com/blog/article/2013020/ff775951d861049c08bf/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

21 0
收藏该文
已收藏

评论内容:(最多支持255个字符)