POSIXt
Date-Time Classes

Description

POSIXct and POSIXlt are classes inherited from POSIXt for representing both date and time.

Usage

.POSIXct(xx, tz = NULL) # generally for internal use
.POSIXlt(xx, tz = NULL) # generally for internal use

## S3 method for class 'POSIXct': print(x, ...) ## S3 method for class 'POSIXlt': print(x, ...)

## S3 method for class 'POSIXct': x[..., drop = TRUE] ## S3 method for class 'POSIXct': x[...] <- value ## S3 method for class 'POSIXct': x[[..., drop = TRUE]]

## S3 method for class 'POSIXlt': x[..., drop = TRUE] ## S3 method for class 'POSIXlt': x[i] <- value

Arguments

xx an S object.
tz a character string representing the time zone.
x a POSIXct or POSIXlt object.
value an S object that can be converted to POSIXct or POSIXlt with as.POSIXct(value) or as.POSIXlt(value) respectively, representing the replacement value for the relevant piece of the object.
drop a logical flag passed to operator [ and [[, respectively.
i an integer value representing the index of vector.
... additional arguments.

Details

Both POSIXct and POSIXlt are inherited from POSIXt for representing both date and time.
POSIXct
The internal representation for POSIXct is structure(i, class = c("POSIXct", "POSIXt")), where i is numeric with positive values representing the number of seconds since the UNIX epoch (that is, 1970-01-01 00:00:00 UTC) and negative values for earlier dates. It can also contain a character attribute tzone of length 1 indicating the time zone. If this attribute is not specified, the current time zone is used when the object is printed.
POSIXlt
The internal representation for POSIXlt is structure(i, class = c("POSIXlt", "POSIXt")), where i is a numeric list of length 11 (or sometimes 9) representing calendar time parsed as follows.
sec
seconds after the minute (double [0, 59]).
min
minutes after the hour (integer [0, 59]).
hour
hours since midnight (integer [0, 23]).
mday
day of the month (integer [1, 31]).
mon
month since January (integer [0, 11], 0 = January).
year
year since 1900 (integer).
wday
day of the week (integer [0, 6], where 0 = Sunday). Not used for input.
yday
day of the year (integer [0, 365]), Not used for input.
isdst
daylight savings time flag (integer [enabled (> 0), disabled (= 0), or unknown (< 0)]).
zone
the abbreviated form of the time zone and daylight/standard time setting
gmtoff
the difference, in seconds, between local time and Greenwich Mean Time (UTC). Negative numbers are west and positive east of Greenwich.
It can also contain a character attribute tzone of length either 1 or 3, indicating the time zone, with the first being the generic name and the second and third (if they exist) the (abbreviated) standard name and daylight savings time name, respectively. The value of isdst determines which time zone name is displayed when the object is printed
isdst < 0
tzone[1].
isdst = 0
tzone[2] if length(tzone) = 3, otherwise tzone[1].
isdst > 0
tzone[3] if length(tzone) = 3, otherwise tzone[1].
Value
.POSIXct, .POSIXlt returns a POSIXct or POSIXlt object, respectively, with the specified time zone.
print returns the original object x, with the invisible flag set to prevent reprinting.
[, [[, [<- returns a POSIXct or POSIXlt object formed by extracting or replacing the relevant subset.
References
Time Zone. http://en.wikipedia.org/wiki/Timezone.
tz database. http://en.wikipedia.org/wiki/Tz_database.
Sources for time zone and daylight saving time data. http://cs.ucla.edu/~eggert/tz/tz-link.htm.
Leap second. http://en.wikipedia.org/wiki/Leap_second.
See Also
as.Date, format.Date, Math.Date, Ops.Date, Summary.Date, Date, Sys.time.
Examples
## show the internal representation of the POSIXct class
dput(Sys.time())

## construct POSIXct objects .POSIXct(0) .POSIXct(0, tz = "UTC")

## construct POSIXlt objects .POSIXlt(list(secs = 1.8, 2, 3, 4, 5, 6, 7, 8, 9)) .POSIXlt(list(secs = 1.8, 2, 3, 4, 5, 6, 7, 8, -1:1), tz = "zone_name") .POSIXlt(list(secs = 1.8, 2, 3, 4, 5, 6, 7, 8, -1:1), tz = c("zone_name", "std_zone_abbrev", "dst_zone_abbrev"))

## subset POSIXlt objects (x <- .POSIXlt(list(secs = 1, 2, 3, 4, 5, 1:9, 0, 0, -1))) x[1] <- Sys.time() # fails in R x[2] <- Sys.Date() # fails in R x[3] <- .POSIXlt(list(secs = 9, 8, 7, 6, 5, 4, 3, 2, 1)) x[1:3] # incorrect in R

Package base version 6.1.4-13
Package Index