EVOLUTION-MANAGER
Edit File: difftime.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Time Intervals / Differences</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for difftime {base}"><tr><td>difftime {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Time Intervals / Differences</h2> <h3>Description</h3> <p>Time intervals creation, printing, and some arithmetic. The <code><a href="print.html">print</a>()</code> method calls these “time differences”. </p> <h3>Usage</h3> <pre> time1 - time2 difftime(time1, time2, tz, units = c("auto", "secs", "mins", "hours", "days", "weeks")) as.difftime(tim, format = "%X", units = "auto") ## S3 method for class 'difftime' format(x, ...) ## S3 method for class 'difftime' units(x) ## S3 replacement method for class 'difftime' units(x) <- value ## S3 method for class 'difftime' as.double(x, units = "auto", ...) ## Group methods, notably for round(), signif(), floor(), ## ceiling(), trunc(), abs(); called directly, *not* as Math(): ## S3 method for class 'difftime' Math(x, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>time1, time2</code></td> <td> <p><a href="DateTimeClasses.html">date-time</a> or <a href="Dates.html">date</a> objects.</p> </td></tr> <tr valign="top"><td><code>tz</code></td> <td> <p>an optional <a href="timezones.html">time zone</a> specification to be used for the conversion, mainly for <code>"POSIXlt"</code> objects.</p> </td></tr> <tr valign="top"><td><code>units</code></td> <td> <p>character string. Units in which the results are desired. Can be abbreviated.</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>character string. Like <code>units</code>, except that abbreviations are not allowed.</p> </td></tr> <tr valign="top"><td><code>tim</code></td> <td> <p>character string or numeric value specifying a time interval.</p> </td></tr> <tr valign="top"><td><code>format</code></td> <td> <p>character specifying the format of <code>tim</code>: see <code><a href="strptime.html">strptime</a></code>. The default is a locale-specific time format.</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>an object inheriting from class <code>"difftime"</code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments to be passed to or from other methods.</p> </td></tr> </table> <h3>Details</h3> <p>Function <code>difftime</code> calculates a difference of two date/time objects and returns an object of class <code>"difftime"</code> with an attribute indicating the units. The <code><a href="groupGeneric.html">Math</a></code> group method provides <code><a href="Round.html">round</a></code>, <code><a href="Round.html">signif</a></code>, <code><a href="Round.html">floor</a></code>, <code><a href="Round.html">ceiling</a></code>, <code><a href="Round.html">trunc</a></code>, <code><a href="MathFun.html">abs</a></code>, and <code><a href="sign.html">sign</a></code> methods for objects of this class, and there are methods for the group-generic (see <code><a href="groupGeneric.html">Ops</a></code>) logical and arithmetic operations. </p> <p>If <code>units = "auto"</code>, a suitable set of units is chosen, the largest possible (excluding <code>"weeks"</code>) in which all the absolute differences are greater than one. </p> <p>Subtraction of date-time objects gives an object of this class, by calling <code>difftime</code> with <code>units = "auto"</code>. Alternatively, <code>as.difftime()</code> works on character-coded or numeric time intervals; in the latter case, units must be specified, and <code>format</code> has no effect. </p> <p>Limited arithmetic is available on <code>"difftime"</code> objects: they can be added or subtracted, and multiplied or divided by a numeric vector. In addition, adding or subtracting a numeric vector by a <code>"difftime"</code> object implicitly converts the numeric vector to a <code>"difftime"</code> object with the same units as the <code>"difftime"</code> object. There are methods for <code><a href="mean.html">mean</a></code> and <code><a href="sum.html">sum</a></code> (via the <code><a href="groupGeneric.html">Summary</a></code> group generic), and <code><a href="diff.html">diff</a></code> via <code><a href="diff.html">diff.default</a></code> building on the <code>"difftime"</code> method for arithmetic, notably <code>-</code>. </p> <p>The units of a <code>"difftime"</code> object can be extracted by the <code>units</code> function, which also has a replacement form. If the units are changed, the numerical value is scaled accordingly. The replacement version keeps attributes such as names and dimensions. </p> <p>Note that <code>units = "days"</code> means a period of 24 hours, hence takes no account of Daylight Savings Time. Differences in objects of class <code>"<a href="Dates.html">Date</a>"</code> are computed as if in the UTC time zone. </p> <p>The <code>as.double</code> method returns the numeric value expressed in the specified units. Using <code>units = "auto"</code> means the units of the object. </p> <p>The <code>format</code> method simply formats the numeric value and appends the units as a text string. </p> <h3>Note</h3> <p>Units such as <code>"months"</code> are not possible as they are not of constant length. To create intervals of months, quarters or years use <code><a href="seq.Date.html">seq.Date</a></code> or <code><a href="seq.POSIXt.html">seq.POSIXt</a></code>. </p> <h3>See Also</h3> <p><code><a href="DateTimeClasses.html">DateTimeClasses</a></code>. </p> <h3>Examples</h3> <pre> (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) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>