[R] POSIXlt and months

Terry Therneau therneau at mayo.edu
Tue Sep 3 13:31:40 CEST 2013


The help page for as.POSIXlt suggests using it as a way to extract month, day, and year.
However, I can't find any documentation on the results and am a bit surprised by the month 
portion.

An example, run about 6:21 AM on Sept 3.

 > unlist(unclass(as.POSIXlt(Sys.time())))

       sec       min      hour      mday       mon      year      wday      yday
  43.24545  21.00000   6.00000   3.00000   8.00000 113.00000   2.00000 245.00000
     isdst
   1.00000


So: it appears that I need to
       add 1900 to year
       add 1 to month
but other components are as I would expect.

 > unlist(unclass(as.POSIXlt(as.Date("1953/03/10"))))
   sec   min  hour  mday   mon  year  wday  yday isdst
     0     0     0    10     2    53     2    68     0

Supports a 0 origin for everything except year and mday.

  A pointer to formal documentation of this would make me feel easier about using the 
function.

Terry Therneau



More information about the R-help mailing list