x <- as.Date("1970-01-01")
x
# [1] "1970-01-01"
unclass(x)
# [1] 0
unclass(as.Date("1970-01-02"))
# [1] 1
more about POSIXct and POSIXlt
x <- Sys.time()
x #[1] "2016-01-14 11:52:33 CST"
p <- as.POSIXlt(x)
[1] "2016-01-15 13:52:49 CST"
names(unclass(p))
# "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst" "zone" "gmtoff
unclass(p)
> str(unclass(p))
List of 11
$ sec : num 49.3
$ min : int 52
$ hour : int 13
$ mday : int 15
$ mon : int 0
$ year : int 116
$ wday : int 5
$ yday : int 14
$ isdst : int 0
$ zone : chr "CST"
$ gmtoff: int -21600
- attr(*, "tzone")= chr [1:3] "" "CST" "CDT"
> t2$min
[1] 52
> weekdays(d1)
[1] "星期五"
> months(t1)
[1] "一月"
> quarters(t2)
[1] "Q1
> difftime(Sys.time(), t1, units = 'days')
Time difference of 0.01489474 days
> Sys.time()>t1
[1] TRUE
t3 <- "October 17, 1986 08:24"
t4 <- strptime(t3, "%B %d, %Y %H:%M")