difftime
Time Intervals

Description

The class difftime represents time intervals.

Usage

.difftime(xx, units) # generally for internal use
difftime(time1, time2, tz, units = c("auto", "secs", "mins", 
   "hours", "days", "weeks"))

## S3 method for class 'difftime': print(x, digits = getOption("digits"), ...) ## S3 method for class 'difftime': [(x, ..., drop = TRUE)

Arguments

xx an S object.
time1, time2 an S object that is inherited from or can be converted to POSIXt, such as POSIXct or POSIXlt objects or date-time strings.
tz a character string representing the time zone, such as "GMT".
units a character string from "auto", "secs", "mins", "hours", "days", and "weeks".
format a character string representing the time format for tim.
x a difftime object.
digits the maximum number of (significant) digits to print.
drop a logical flag passed to operator [.
... additional arguments.

Details

A difftime object is internally represented as structure(i, units = "hours", class = "difftime"), where i is numeric representing the number of units.
Value
.difftime returns a difftime object with specified units.
difftime returns a difftime object, representing the time difference between time1 and time2.
print.difftime returns the original object x, with the invisible flag set to prevent reprinting.
[.difftime returns a difftime object formed by extracting the relevant subset.
Differences between TIBCO Enterprise Runtime for R and Open-source R
Differences exist between TIBCO Enterprise Runtime for R and open-source R in the results for calculating difftime near DST; the TIBCO Enterprise Runtime for R results appear more reasonable than those of open-source R.
Example
## The start of DST in USA 2013 is 2013-03-10 2:00AM > difftime("2013-03-10 03:00:00", "2013-03-10 02:00:00", tz = "America/New_York") # Time difference of 2 hours (open-source R) # Time difference of 0 secs (TERR) > difftime("2013-03-10 03:00:00", "2013-03-10 02:59:00", tz = "America/New_York") # Time difference of 2 hours (open-source R) # Time difference of -59 mins (TERR) The differences are caused by the differences in as.POSIXct, i.e., > as.POSIXct("2013-03-10 02:00:00", tz = "America/New_York") # [1] "2013-03-10 EST" (open-source R) # [1] "2013-03-10 03:00:00 EDT" (TERR) > as.POSIXct("2011-03-13 02:59:59", tz = "America/New_York") # [1] "2013-03-10 EST" (open-source R) # [1] "2013-03-10 03:59:59 EDT" (TERR)
See Also
Math.difftime, Ops.difftime, Summary.difftime, Date, POSIXt, as.Date, format.Date, units.
Examples
## show the internal representation of the difftime class
dput(.difftime(24, units = "hours"))

## construct difftime objects difftime(time1 = .POSIXct(0), time2 = "1970-01-01 00:00:00") difftime(time1 = .POSIXct(0), time2 = "1970-01-01 00:00:00", tz = "UTC") difftime("2038-01-19 03:14:07", "1970-01-01 00:00:00", units = "secs") # compare with 2^31 - 1 (the Unix Millennium Bug)

## subset difftime objects (x <- as.difftime(c("0:0:1", "0:1:0", "1:0:0"))) x[2:3]

Package base version 4.0.0-28
Package Index