Rev 10953 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{DateTimeClasses}\alias{POSIXct}\alias{POSIXlt}\alias{print.POSIXct}\alias{print.POSIXlt}\alias{summary.POSIXct}\alias{summary.POSIXlt}\alias{+.POSIXct}\alias{-.POSIXct}\alias{Ops.POSIXct}\alias{Math.POSIXct}\alias{Summary.POSIXct}\alias{+.POSIXlt}\alias{-.POSIXlt}\alias{Ops.POSIXlt}\alias{Math.POSIXlt}\alias{Summary.POSIXlt}\alias{[.POSIXct}\alias{[<-.POSIXct}\alias{[[.POSIXct}\alias{as.data.frame.POSIXct}\alias{.leap.seconds}\alias{is.na.POSIXlt}\alias{all.equal.POSIXct}\alias{c.POSIXct}\alias{c.POSIXlt}\alias{as.matrix.POSIXlt}\title{Date-Time Classes}\description{Description of the classes \code{"POSIXlt"} and \code{"POSIXct"}representing calendar dates and times (to the nearest second).}\usage{print.POSIXct(x, ...)print.POSIXlt(x, ...)summary.POSIXct(object, digits = 15, ...)summary.POSIXlt(object, digits = 15, ...)time + numbertime - numbertime1 lop time2}\arguments{\item{x, object}{An object to be printed or summarized.}\item{digits}{Number of significant digits for the computations:should be high enough to represent the least important time unitexactly.}\item{\dots}{Further arguments to be passed from or to other methods.}\item{time, time1, time2}{date-time objects.}\item{number}{a numeric object.}\item{lop}{One of \code{==}, \code{!=}, \code{<}, \code{<=}, \code{>}or \code{>=}.}}\details{There are two basic classes of date/times. Class \code{"POSIXct"}represents the (signed) number of seconds since the beginning of 1970as a numeric vector. Class \code{"POSIXlt"} is a named list ofvectors representing\describe{\item{\code{sec}}{0--61: seconds}\item{\code{min}}{0--59: minutes}\item{\code{hour}}{0--23: hours}\item{\code{mday}}{1--31: day of the month}\item{\code{mon}}{0--11: months after the first of the year.}\item{\code{year}}{Years since 1900.}\item{\code{wday}}{0--6 day of the week, starting on Sunday.}\item{\code{yday}}{0--365: day of the year.}\item{\code{isdst}}{Daylight savings time flag. Positive if inforce, zero if not, negative if unknown.}}The classes correspond to the ANSI C constructs of ``calendar time''(the \code{time\_t} data type) and ``local time'' (or broken-downtime, the \code{struct tm} data type), from which they also inherittheir names.\code{"POSIXct"} is more convenient for including in data frames, and\code{"POSIXlt"} is closer to human-readable forms. Logicalcomparisons and limited arithmetic are available for both classes.Differences between objects are returned as the number of (non-leap)seconds between them. One can add or subtract a number of secondsfrom a date-time object, but not add two date-time objects.\code{"POSIXlt"} objects will often have an attribute \code{"tzone"},a character vector of length 3 giving the timezone name from the\code{"TZ"} environment variable and the names of the base timezoneand the alternate (daylight-saving) timezone.Unfortunately, the conversion is complicated by the operation of timezones and leap seconds (22 days have been 86401 seconds long so far:the times of the extra seconds are in the object \code{.leap.seconds}).The details of this are entrusted to the OS services where possible.This will usually cover the period 1970--2037, and on Unix machinesback to 1902 (when time zones were in their infancy). Outside thoseranges we use our own C code. This uses the offset from GMT in usein the timezone in 2000, and uses the alternate (daylight-saving)timezone only if \code{isdst} is positive.It seems that some systems use leap seconds but most do not. This isdetected and corrected for at build time, so all \code{"POSIXct"}times used by \R do not include leap seconds. (Conceivably this couldbe wrong if the system has changed since build time, just possibly bychanging locales.)}\seealso{\code{\link{as.POSIXct}} and \code{\link{as.POSIXlt}} for conversionbetween the classes.\code{\link{strptime}} for conversion to and from characterrepresentations.\code{\link{Sys.time}} for clock time as a \code{"POSIXct"} object.}\section{Warning}{Some Unix-like systems (especially Linux ones) do not have \code{"TZ"}set, yet have internal code that expects it (as does POSIX). We havetried to work around this, but if you get unexpected results trysetting \code{"TZ"}.}\examples{(z <- Sys.time()) # the current date, as class "POSIXct"(z <- Sys.time() - 3600) # an hour agoSys.time() - z # just over 3600 seconds.as.POSIXlt(Sys.time(), "GMT") # the current time in GMTformat(.leap.seconds) # all 22 leapseconds in your timezone}\keyword{utilities}\keyword{chron}