w3resource

Python Arrow Module: Get hourly datetime between two hours


Write a Python program to get hourly datetime between two hours.

Sample Solution:

Python Code:

import arrow
a = arrow.utcnow()
print("Current datetime:")
print(a)
print("\nString representing the date, controlled by an explicit format string:")
print(arrow.utcnow().strftime('%d-%m-%Y %H:%M:%S'))
print(arrow.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
print(arrow.utcnow().strftime('%Y-%d-%m %H:%M:%S'))

Sample Output:

2019-06-04T11:00:00+00:00

2019-06-04T11:59:59.999999+00:00
2019-06-04T12:00:00+00:00

2019-06-04T12:59:59.999999+00:00
2019-06-04T13:00:00+00:00

2019-06-04T13:59:59.999999+00:00
2019-06-04T14:00:00+00:00

2019-06-04T14:59:59.999999+00:00
2019-06-04T15:00:00+00:00

2019-06-04T15:59:59.999999+00:00
2019-06-04T16:00:00+00:00

2019-06-04T16:59:59.999999+00:00

Python Code Editor:

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

Previous: Write a Python program to get string representing the date, controlled by an explicit format string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.