What type to store time length in python?

I used:

total_time=datetime.time(int(total_time_text.replace("h","").replace("m","").split(" ")[0]),int(total_time_text.replace("h","").replace("m","").split(" ")[1]),0) 

to save the length of time.

But when I have:

 total_time_text ="26h 50m" 

I get an exception that

 'hour must be in 0..23' 

therefore, the time type is not suitable for this var. What should i use?

+6
source share
3 answers

See PLEAC for many date / time examples.

0
source

If you want to keep the length of time, you probably won't want to use datetime.time (which is for a specific time per day, not for duration). You should use datetime.timedelta or even a simple integer representing the number of seconds (or minutes).

0
source

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


All Articles