Time intervals creation, printing, and some arithmetic. The print() method calls these “time differences”.
<code>time1 - time2</code><p></p><p>difftime(time1, time2, tz,
units = c("auto", "secs", "mins", "hours",
"days", "weeks"))</p><p>as.difftime(tim, format = "%X", units = "auto")</p><p># S3 method for difftime
format(x, ...)
# S3 method for difftime
units(x)
# S3 method for difftime
units(x) <- value
# S3 method for difftime
as.double(x, units = "auto", ...)</p><p>## Group methods, notably for round(), signif(), floor(),
## ceiling(), trunc(), abs(); called directly, *not* as Math():
# S3 method for difftime
Math(x, …)</p>
| Parameter | Description |
|---|---|
time1, time2 |
date-time or date objects. |
tz |
an optional time zone specification to be used for the conversion, mainly for "POSIXlt" objects. |
units |
character string. Units in which the results are desired. Can be abbreviated. |
value |
character string. Like units, except that abbreviations are not allowed. |
tim |
character string or numeric value specifying a time interval. |
format |
character specifying the format of tim: see strptime. The default is a locale-specific time format. |
x |
an object inheriting from class "difftime". |
… |
arguments to be passed to or from other methods. |
# NOT RUN {
(z <- Sys.time() - 3600)
Sys.time() - z # just over 3600 seconds.
## time interval between release days of R 1.2.2 and 1.2.3.
ISOdate(2001, 4, 26) - ISOdate(2001, 2, 26)
as.difftime(c("0:3:20", "11:23:15"))
as.difftime(c("3:20", "23:15", "2:"), format = "%H:%M") # 3rd gives NA
(z <- as.difftime(c(0,30,60), units = "mins"))
as.numeric(z, units = "secs")
as.numeric(z, units = "hours")
format(z)
# }