TimeSpan class represents a time interval.
See also
__init__ | Default constructor, constructs a zero timespan. |
Abs | Returns the absolute value of the timespan: does not modify the object. |
Add | Adds the given TimeSpan to this TimeSpan and returns a reference to itself. |
Day | Returns the timespan for one day. |
Days | Returns the timespan for the given number of days. |
Format | Returns the string containing the formatted representation of the time span. |
GetDays | Returns the difference in number of days. |
GetHours | Returns the difference in number of hours. |
GetMilliseconds | Returns the difference in number of milliseconds. |
GetMinutes | Returns the difference in number of minutes. |
GetSeconds | Returns the difference in number of seconds. |
GetValue | Returns the internal representation of timespan. |
GetWeeks | Returns the difference in number of weeks. |
Hour | Returns the timespan for one hour. |
Hours | Returns the timespan for the given number of hours. |
IsEqualTo | Returns True if two timespans are equal. |
IsLongerThan | Compares two timespans: works with the absolute values, i.e. |
IsNegative | Returns True if the timespan is negative. |
IsNull | Returns True if the timespan is empty. |
IsPositive | Returns True if the timespan is positive. |
IsShorterThan | Compares two timespans: works with the absolute values, i.e. |
Millisecond | Returns the timespan for one millisecond. |
Milliseconds | Returns the timespan for the given number of milliseconds. |
Minute | Returns the timespan for one minute. |
Minutes | Returns the timespan for the given number of minutes. |
Multiply | Multiplies this time span by n. |
Neg | Negate the value of the timespan. |
Negate | Returns timespan with inverted sign. |
Second | Returns the timespan for one second. |
Seconds | Returns the timespan for the given number of seconds. |
Subtract | Subtracts the given TimeSpan to this TimeSpan and returns a reference to itself. |
Week | Returns the timespan for one week. |
Weeks | Returns the timespan for the given number of weeks. |
TimeSpan class represents a time interval.
Possible constructors:
TimeSpan()
TimeSpan(hours, min=0, sec=0, msec=0)
Overloaded Implementations:
__init__ (self)
Default constructor, constructs a zero timespan.
__init__ (self, hours, min=0, sec=0, msec=0)
Constructs timespan from separate values for each component, with the date set to 0.
Hours are not restricted to 0-24 range, neither are minutes, seconds or milliseconds.
Parameters: |
|
---|
Returns the absolute value of the timespan: does not modify the object.
Return type: | TimeSpan |
---|
Returns the timespan for the given number of days.
Parameters: | days (long) – |
---|---|
Return type: | TimeSpan |
Returns the string containing the formatted representation of the time span.
The following format specifiers are allowed after %:
Note that, for example, the number of hours in the description above is not well defined: it can be either the total number of hours (for example, for a time span of 50 hours this would be 50) or just the hour part of the time span, which would be 2 in this case as 50 hours is equal to 2 days and 2 hours.
TimeSpan resolves this ambiguity in the following way: if there had been, indeed, the D format specified preceding the H , then it is interpreted as 2. Otherwise, it is 50.
The same applies to all other format specifiers: if they follow a specifier of larger unit, only the rest part is taken, otherwise the full value is used.
Parameters: | format (string) – |
---|---|
Return type: | string |
Returns the difference in number of days.
Return type: | int |
---|
Returns the difference in number of hours.
Return type: | int |
---|
Returns the difference in number of milliseconds.
Return type: | long |
---|
Returns the difference in number of minutes.
Return type: | int |
---|
Returns the difference in number of seconds.
Return type: | long |
---|
Returns the internal representation of timespan.
Return type: | long |
---|
Returns the difference in number of weeks.
Return type: | int |
---|
Returns the timespan for the given number of hours.
Parameters: | hours (long) – |
---|---|
Return type: | TimeSpan |
Returns True if two timespans are equal.
Parameters: | ts (TimeSpan) – |
---|---|
Return type: | bool |
Compares two timespans: works with the absolute values, i.e.
-2 hours is longer than 1 hour. Also, it will return False if the timespans are equal in absolute value.
Parameters: | ts (TimeSpan) – |
---|---|
Return type: | bool |
Returns True if the timespan is negative.
Return type: | bool |
---|
Returns True if the timespan is empty.
Return type: | bool |
---|
Returns True if the timespan is positive.
Return type: | bool |
---|
Compares two timespans: works with the absolute values, i.e.
1 hour is shorter than -2 hours. Also, it will return False if the timespans are equal in absolute value.
Parameters: | ts (TimeSpan) – |
---|---|
Return type: | bool |
Returns the timespan for the given number of milliseconds.
Parameters: | ms (long) – |
---|---|
Return type: | TimeSpan |
Returns the timespan for the given number of minutes.
Parameters: | min (long) – |
---|---|
Return type: | TimeSpan |
Multiplies this time span by n.
Returns: | A reference to this TimeSpan object modified in place. |
---|
Returns the timespan for the given number of seconds.
Parameters: | sec (long) – |
---|---|
Return type: | TimeSpan |
Subtracts the given TimeSpan to this TimeSpan and returns a reference to itself.