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.
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))
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?
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework