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 represents 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,
i.e., 1970-01-01 00:00:00 UTC and negative values the earlier dates.
It may 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 9 representing the broken-down time, i.e., calendar time separated into
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], 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)])
It may 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 the third (if exist) the (abbreviated) standard name and daylight savings name respectively.
The value of
isdst determines which time zone name gets 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
See Also
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