G
G
Gennady2018-10-09 17:19:27
Python
Gennady, 2018-10-09 17:19:27

How to round time in python?

Good afternoon!
For example, I have a number of seconds, 3590
, using timedelta I can get a string representation, such as 00:59:50
And I need to round up to 1 hour
Guys, tell me, is there any simple way or library to round time in Python?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-10-09
@genana40

Divide your number of seconds by the number of seconds in an hour (3600) to get the number of hours. Round it up to a whole number (round method), then multiply by 3600. As a result, you will get the number of seconds in an integer number of hours.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question