Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 箭头中时间戳之间的差异_Python_Datetime_Arrow Python - Fatal编程技术网

Python 箭头中时间戳之间的差异

Python 箭头中时间戳之间的差异,python,datetime,arrow-python,Python,Datetime,Arrow Python,如何让Arrow返回两个时间戳之间的小时差 以下是我所拥有的: difference = arrow.now() - arrow.get(p.create_time()) print(difference.hour) p.create_time()是当前正在运行的进程的创建时间的时间戳 返回: AttributeError: 'datetime.timedelta' object has no attribute 'hour' 编辑:我不想要所有三种格式的总时间,我想要它作为余数,例如“3天

如何让Arrow返回两个时间戳之间的小时差

以下是我所拥有的:

difference = arrow.now() - arrow.get(p.create_time())
print(difference.hour)
p.create_time()
是当前正在运行的进程的创建时间的时间戳

返回:

AttributeError: 'datetime.timedelta' object has no attribute 'hour'

编辑:我不想要所有三种格式的总时间,我想要它作为余数,例如“3天,4小时,36分钟”而不是“3天,72小时,4596分钟”

给定的两个日期的格式是从字符串到
箭头
类型

>>> date_1 = arrow.get('2015-12-23 18:40:48','YYYY-MM-DD HH:mm:ss')
>>> date_2 = arrow.get('2017-11-15 13:18:20','YYYY-MM-DD HH:mm:ss')
>>> diff = date_2 - date_1
区别在于数据类型

>>> print type(diff)
<type 'datetime.timedelta'>
要将其格式化,使您有
D天、H小时、M分钟、S秒
,您可以分别获得这些天,然后使用
divmod
函数获取其他信息

>>> days = diff.days # Get Day 
>>> hours,remainder = divmod(diff.seconds,3600) # Get Hour 
>>> minutes,seconds = divmod(remainder,60) # Get Minute & Second 
结果将是:

>>> print days, " Days, ", hours, " Hours, ", minutes, " Minutes, ", seconds, " Second"
692  Days,  18  Hours,  37  Minutes,  32  Second

“接近”是的副本。@alecxe请查看我的编辑。可能是的副本
>>> print days, " Days, ", hours, " Hours, ", minutes, " Minutes, ", seconds, " Second"
692  Days,  18  Hours,  37  Minutes,  32  Second