%b %B %d %m %y %Y
> d = Sys.Date( ) > cat(format(d, format="%B %d, %Y\n")) May 18, 2015
> d <- as.Date("1776-7-4") > e <- as.Date("1856/12/25") > f <- as.Date("1970/1/1") > print(d) [1] "1776-07-04" > print(e) [1] "1856-12-25" > print(f) [1] "1970-01-01" >To create dates from strings in other formats, a format specifier is required:
> g <- as.Date("12.25.1956", format="%m.%d.%Y") > print(g) [1] "1956-12-25"
> n = as.numeric(f) > print(n) [1] 1
> d = as.Date(Sys.Date( )) > as.integer(d) [1] 15844 > d = as.Date("1970-1-1") > as.integer(d) [1] 0
> s <- as.Date("2009-1-1") > e <- as.Date("2010-12-1") > series1 <- seq(s, e, by=1) > series2 <- seq(s, e, by="day") > series3 <- seq(s, e, by="month") > series4 <- seq(s, e, by="3 months") > series5 <- seq(s, e, by="year") > print(series1) > print(series2) > print(series3) > print(series4) > print(series5) [1] "2009-01-01" "2009-01-02" "2009-01-03" "2009-01-04" "2009-01-05" [6] "2009-01-06" "2009-01-07" "2009-01-08" "2009-01-09" "2009-01-10" ... ... Lines omitted from display. ... [691] "2010-11-22" "2010-11-23" "2010-11-24" "2010-11-25" "2010-11-26" [696] "2010-11-27" "2010-11-28" "2010-11-29" "2010-11-30" "2010-12-01" > print(series2) [1] "2009-01-01" "2009-01-02" "2009-01-03" "2009-01-04" "2009-01-05" [6] "2009-01-06" "2009-01-07" "2009-01-08" "2009-01-09" "2009-01-10" ... ... Lines omitted from display. ... [691] "2010-11-22" "2010-11-23" "2010-11-24" "2010-11-25" "2010-11-26" [696] "2010-11-27" "2010-11-28" "2010-11-29" "2010-11-30" "2010-12-01" > print(series3) [1] "2009-01-01" "2009-02-01" "2009-03-01" "2009-04-01" "2009-05-01" [6] "2009-06-01" "2009-07-01" "2009-08-01" "2009-09-01" "2009-10-01" [11] "2009-11-01" "2009-12-01" "2010-01-01" "2010-02-01" "2010-03-01" [16] "2010-04-01" "2010-05-01" "2010-06-01" "2010-07-01" "2010-08-01" [21] "2010-09-01" "2010-10-01" "2010-11-01" "2010-12-01" > print(series4) [1] "2009-01-01" "2009-04-01" "2009-07-01" "2009-10-01" "2010-01-01" [6] "2010-04-01" "2010-07-01" "2010-10-01" > print(series5) [1] "2009-01-01" "2010-01-01"
> as.Date("2012-2-29") [1] "2012-02-29" > as.Date("2000-2-29") [1] "2000-02-29" > as.Date("1900-2-29") Error in charToDate(x) : character string is not in a standard unambiguous format
> ISOdate(1978, 3, 2) [1] "1978-03-02 12:00:00 GMT" > ISOdatetime(1978, 3, 2, 14, 23, 34) [1] "1978-03-02 14:23:34 CST"
> as.POSIXct(as.Date("2012-5-20")) [1] "2012-05-19 19:00:00 CDT" > as.POSIXct(Sys.Date()) [1] "2013-05-18 19:00:00 CDT"
> d <- as.Date("2013-5-20") > p <- as.POSIXlt(d) > p$year [1] 113 > p$mon [1] 4 > p$mday [1] 20 > p$wday [1] 1 > p$yday [1] 139 > p [1] "2013-05-20 UTC" > attributes(p) $names [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst" $class [1] "POSIXlt" "POSIXt" $tzone [1] "UTC"
> format(.leap.seconds) [1] "1972-06-30 19:00:00" "1972-12-31 18:00:00" "1973-12-31 18:00:00" [4] "1974-12-31 18:00:00" "1975-12-31 18:00:00" "1976-12-31 18:00:00" [7] "1977-12-31 18:00:00" "1978-12-31 18:00:00" "1979-12-31 18:00:00" [10] "1981-06-30 19:00:00" "1982-06-30 19:00:00" "1983-06-30 19:00:00" [13] "1985-06-30 19:00:00" "1987-12-31 18:00:00" "1989-12-31 18:00:00" [16] "1990-12-31 18:00:00" "1992-06-30 19:00:00" "1993-06-30 19:00:00" [19] "1994-06-30 19:00:00" "1995-12-31 18:00:00" "1997-06-30 19:00:00" [22] "1998-12-31 18:00:00" "2005-12-31 18:00:00" "2008-12-31 18:00:00" [25] "2012-06-30 19:00:00"