[R] convert from seconds to date-time objects

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Feb 3 18:26:03 CET 2003

Thomas Lumley <tlumley at u.washington.edu> writes:

> On Mon, 3 Feb 2003, John Bjornar Bremnes wrote:
> > A colleague of mine would like to know how seconds since 1970
> > (represented as integers) can be converted to date-time objects?
> ISOdate(1970,1,1)+seconds

I think you might want 


to get it to count from midnight, GMT.

Notice that there are devils lurking in using class(x)<-

> class(ISOdate(1970,1,1,hour=0)+1:100)
[1] "POSIXt"  "POSIXct"

so that's what you need to set class(x) to. Without the "POSIXt" bit
you may run into method dispatch problems later on. Currently, that
is! Relying on the internal representation of a class is generally to
be avoided.

   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

More information about the R-help mailing list