Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type to store time length in python?

I was using :

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 store the time length.

But when I have :

total_time_text ="26h 50m"

I get an exception that

'hour must be in 0..23'

so the type "time" is not properly for this var. What I must to use?

like image 663
user278618 Avatar asked Jul 05 '11 08:07

user278618


People also ask

What are the basic date and time types in Python?

Python Basic date and time types Sr.No. Datatypes & Description 1 date It is date type object. It uses Gre ... 2 time It is a time object class. It is in ... 3 datetime It is a combined set of dates a ... 4 timedelta It is used to express the diff ... 2 more rows ...

What is the use of time in Python?

Time module in Python provides various time-related functions. This module comes under Python’s standard utility modules. time.time () method of Time module is used to get the time in seconds since epoch.

How to measure a span of time using Python datetime?

Often, we may want to measure a span of time, or a duration, using Python datetime. We can do this with its built-in timedelta class. A timedelta object represents the amount of time between two dates or times.

How to manipulate dates and times in Python?

To manipulate dates and times in the python there is a module called datetime. There are two types of date and time objects. The types are naïve and the aware. In the naïve object, there is no enough information to unambiguously locate this object from other date-time objects.


1 Answers

datetime.timedelta

like image 138
phihag Avatar answered Oct 10 '22 04:10

phihag