w3resource

Python Arrow Module: Create a localized, humanized representation of a relative difference in time using arrow module

Arrow Module: Exercise-18 with Solution

Write a Python program to create a localized, humanized representation of a relative difference in time using arrow module.

Sample Solution:

Python Code:

import arrow
print("Current datetime:")
print(arrow.utcnow())
earlier = arrow.utcnow().shift(hours=-4)
print(earlier.humanize())
later = earlier.shift(hours=3)
print(later.humanize(earlier))

Sample Output:

Current datetime:
2019-06-01T11:59:21.976000+00:00
4 hours ago
in 3 hours 

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to create a new Arrow object, representing the "floor" of the timespan of the Arrow object in a given timeframe using arrow module. The timeframe can be any datetime property like day, hour, minute.
Next: Write a Python program to check whether a given datetime is between two dates and times using arrow module.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/arrow/python-arrow-exercise-18.php