Initializes a new timespan value with specified day, hour, minute, second, and millisecond portions.
Syntax
static timespan timespan.New(int days, int hours, int minutes, int seconds, int milliseconds)
Parameters
Parameter | Type | Description |
---|---|---|
days (required) | int | The number of complete days in the time interval. |
hours (required) | int | The number of complete hours in the time interval. |
minutes (required) | int | The number of complete minutes in the time interval. |
seconds (required) | int | The number of complete seconds in the time interval. |
milliseconds (required) | int | The number of milliseconds in the time interval. |
Returns
A new timespan
value with the days, hours, minutes, seconds, and second-fraction
parameters as its day, hour, minute, second, and millisecond portions, respectively.
Remarks
Subtracting two dtl
or
two dtu
values from one
another also results in a timespan value. Only values of the same type may be subtracted.
The method converts each parameter to milliseconds and then adds them up to create the
timespan
value. If one of the parameters is a negative number, its
milliseconds equivalent will get subtracted from the sum of the other parameters. To create a
negative time interval with the actual passed-in parameters, make all of the parameters
negative.
Sample
var a = dtl.New(1605, 11, 05, 6, 45, 32, 43); var b = dtl.New(1914, 7, 28, 5, 42, 21, 10); var c = dtu.New(1605, 11, 05, 6, 45, 32, 43); var d = dtu.New(1914, 7, 28, 5, 42, 21, 10); ... trace (b - a); trace (a - b); trace (d - c); trace (c - d); tracetimespan.New(4, 3, 2, 1, 60)
; trace "This timespan is a negative value, but not with the passed-in parameters",timespan.New(-6, 5, 4, 3, 2)
; trace "For a negative timespan with the passed-in parameters, make all of them negative",timespan.New(-6, -5, -4, -3, -2)
;
112758.22:56:48.9670000 -112758.22:56:48.9670000 112758.22:56:48.9670000 -112758.22:56:48.9670000 4.03:02:01.0600000 "This timespan is a negative value, but not with the passed-in parameters", -5.18:55:56.9980000 "For a negative timespan with the passed-in parameters, make all of them negative", -6.05:04:03.0020000
Figure 377. The trace message output of the script above