duration
create a duration - duration in hours, minutes and seconds
Syntax
d = duration(h, m, s) d = duration(h, m, s, ms) d = duration(x) d = duration(str) d = duration(str, "InputFormat", inputFormat) d = duration(..., "OutputFormat", outputFormat)
Arguments
- h, m, s, ms
hour, minute, second, millisecond
real scalar or matrix
- x
m-by-3 matrix, [h, m, s]
- str
string, vector or matrix of strings
- inputFormat
format of str available: 'dd:hh:mm:ss', 'hh:mm:ss', 'hh:mm', 'mm:ss', 'dd:hh:mm:ss.SSS', 'hh:mm:ss.SSS', 'mm:ss.SSS'
'hh:mm:ss' and "dd:hh:mm:ss" are the default input formats
- outputFormat
display format, string. 'hh:mm:ss' is the default output format.
- d
duration object.
Description
The duration function represents an elapsed times as hours, minutes, seconds. It is possible to create a duration in days (24 hours per day) and in years (365.2425 day per year (Georgian calendar)). For durations in calendar units, see the calendarDuration function.
d = duration(h, m, s [, ms]) creates a duration object based on h, m, s and ms if specified.
d = duration(x) creates a column duration object. x contains the hours, minutes and seconds, one time unit per column.
d = duration(str) creates a duration object based on str writting either hh:mm:ss, or dd:hh:mm:ss. If the format of str does not match the default formats, then d = duration(str, 'InputFormat', inputFormat) has to be used.
For each call of duration, it is possible to specify the display format by using 'OutputFormat' option that changes only the display in Scilab console. The syntax to use is d = duration(..., 'OutputFormat', outputFormat).
Here is the list of available input and output formats: "dd:hh:mm:ss", "hh:mm:ss", "hh:mm", "mm:ss", 'dd:hh:mm:ss.SSS', 'hh:mm:ss.SSS', 'mm:ss.SSS'
duration([]) creates a 0x0 duration object.
Examples
Empty duration
duration([])
Create duration in hours, minutes, seconds, milliseconds
// duration(h, 0, 0) == hours(h) d = duration(0:2:4, 0, 0)' // duration(0, mi, 0) == minutes(mi) d = duration(0, 0:15:60, 0)' // duration(0, 0, s) == seconds(s) d = duration(0, 0, 0:5:59)' // duration(0, 0, 0, ms) == milliseconds(ms) d = duration(0, 0, 0, 0:100:1000)
Create vectors or matrices of duration
d = duration(12, 30, 45) d = duration(0:4:23, 0:10:59, 30) d = d' d = duration(12, 30, 45, 300) d = duration(0:4:23, 0:10:59, 0:10:59, 500) d = duration([12 30 45]) d = duration([2 50 17; 6 22 23; 12 30 45]) d = duration("12:30:45") d = duration(["2:50:17"; "6:22:23"; "12:30:45"])
With InputFormat
d = duration("2:10:50:30", "InputFormat", "dd:hh:mm:ss") d = duration("10:50", "InputFormat", "hh:mm") d = duration("10:50", "InputFormat", "mm:ss") d = duration("10:50.500", "InputFormat", "mm:ss.SSS")
With OutputFormat
d = duration("00:30:45", "OutputFormat", "mm:ss") d = duration("48:50", "InputFormat", "hh:mm", "OutputFormat", "dd:hh:mm:ss")
Extraction - insertion - computation
d1 = duration("09:23:14"); d2 = duration("14:06:57"); d = [d1 d2] d = [d1; d2] d(1) d(1) = d1 + minutes(10) d + minutes(30) d = duration("00:00:00"):hours(2):duration("12:00:00"); size(d)
With datetime function
See also
Report an issue | ||
<< datevec | Time and Date | eomday >> |