The difference between timestamps in the arrow

How do I get an arrow to return the difference in hours between two timestamps?

Here is what I have:

difference = arrow.now() - arrow.get(p.create_time())
print(difference.hour)

p.create_time() is the timestamp of the creation of the currently running process.

Return:

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

Edit: I do not want the total time in all three formats, I want this as a remainder, for example. "3 days, 4 hours, 36 minutes" not "3 days, 72 hours, 4596 minutes"

+4
source share
1 answer

For two dates formatted from string to type arrow.

>>> 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

The difference is in type datetime.timedelta.

>>> print type(diff)
<type 'datetime.timedelta'>

And the results:

>>> print diff
692 days, 18:37:32

, D days, H hours, M minutes, S seconds, , 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
+3

Source: https://habr.com/ru/post/1664737/


All Articles