ID EN
Date & Time

DateTimeClasses

R Base 3.6.2

Description of the classes "POSIXlt" and "POSIXct" representing calendar dates and times.

Syntax

R
# S3 method for POSIXct
print(x, tz = "", usetz = TRUE, max = NULL, &#8230;)<p></p><p># S3 method for POSIXct
summary(object, digits = 15, &#8230;)</p><p><code>time + z</code>
<code>z + time</code>
<code>time - z</code>
<code>time1 lop time2</code></p>

Arguments

Parameter Description
x, object an object to be printed or summarized from one of the date-time classes.
tz, usetz for timezone formatting, passed to format.POSIXct.
max numeric or NULL, specifying the maximal number of entries to be printed. By default, when NULL, getOption("max.print") used.
digits number of significant digits for the computations: should be high enough to represent the least important time unit exactly.
&#8230; further arguments to be passed from or to other methods.
time date-time objects
time1, time2 date-time objects or character vectors. (Character vectors are converted by as.POSIXct.)
z a numeric vector (in seconds)
lop one of ==, !=, <, <=, > or >=.

Details

There are two basic classes of date/times. Class "POSIXct" represents the (signed) number of seconds since the beginning of 1970 (in the UTC time zone) as a numeric vector. Class "POSIXlt" is a named list of vectors representing sec0--61: seconds. min0--59: minutes. hour0--23: hours. mday1--31: day of the month mon0--11: months after the first of the year. yearyears since 1900. wday0--6 day of the week, starting on Sunday. yday0--365: day of the year. isdstDaylight Saving Time flag. Positive if in force, zero if not, negative if unknown. zone(Optional.) The abbreviation for the time zone in force at that time: "" if unknown (but "" might also be used for UTC). gmtoff(Optional.) The offset in seconds from GMT: positive values are East of the meridian. Usually NA if unknown, but 0 could mean

Examples

Example
R
# NOT RUN {
<!-- % <--> may fail / be platform dependent -->
(z <- Sys.time())             # the current date, as class "POSIXct"

Sys.time() - 3600             # an hour ago

as.POSIXlt(Sys.time(), "GMT") # the current time in GMT
format(.leap.seconds)         # the leap seconds in your time zone
print(.leap.seconds, tz = "PST8PDT")  # and in Seattle's
# }
# NOT RUN {
<!-- % ..test should be diffable from here on: -->
# }
# NOT RUN {
## look at *internal* representation of "POSIXlt" :
leapS <- as.POSIXlt(.leap.seconds)
names(leapS) ; is.list(leapS)
## str() "too smart" -->  need unclass(.):
utils::str(unclass(leapS), vec.len = 7)
## Extracting *single* components of POSIXlt objects:
leapS[1 : 5, "year"]

##  length(.) <- n   now works for "POSIXct" and "POSIXlt" :
for(lpS in list(.leap.seconds, leapS)) {
    ls <- lpS; length(ls) <- 12
    l2 <- lpS; length(l2) <- 5 + length(lpS)
    stopifnot(exprs = {
      ## length(.) <- * is compatible to subsetting/indexing:
      identical(ls, lpS[seq_along(ls)])
      identical(l2, lpS[seq_along(l2)])
      ## has filled with NA's
      is.na(l2[(length(lpS)+1):length(l2)])
    })
}
# }
# NOT RUN {
<!-- % for -->
# }

See Also

Dates for dates without times. as.POSIXct and as.POSIXlt for conversion between the classes. strptime for conversion to and from character representations. Sys.time for clock time as a "POSIXct" object. difftime for time intervals. cut.POSIXt seq.POSIXt round.POSIXt and trunc.POSIXt for methods for these classes. weekdays for convenience extraction functions.