Dear R users, I am struggling a bit with the converting dates to full POSIX timestamps, in particular, I would like to somehow force the timezone to be local, i.e. the output of as.POSIXct(as.Date("2008-07-01")) should always be equal to "2008-07-01 00:00:00", is that achievable ? I tried to set the origin and the timezone, neither of which seems to make a difference. On my Mac Book Pro (R version 2.9.1) which is set to Eastern US time zone, I obtain the shifted result:> as.POSIXct(as.Date("2008-07-01"))[1] "2008-06-30 20:00:00 EDT" And e.g.> as.POSIXct( Sys.Date())[1] "2009-09-17 20:00:00 EDT"> Sys.time()[1] "2009-09-18 10:10:48 EDT" Any help would make life simpler for me. Thanks, Markus [[alternative HTML version deleted]]
Gabor Grothendieck
2009-Sep-18 14:49 UTC
[R] as.POSIXct(as.Date()) independent of timezone
Try this:> as.POSIXct(format(as.Date("2008-07-01")))[1] "2008-07-01 EDT" See R News 4/1 for more. On Fri, Sep 18, 2009 at 10:19 AM, Markus Loecher <markus.loecher at gmail.com> wrote:> Dear R users, > I am struggling a bit with the converting dates to full POSIX timestamps, in > particular, I would like to somehow force the timezone to be local, i.e. the > output of > as.POSIXct(as.Date("2008-07-01")) should always be equal to "2008-07-01 > 00:00:00", is that achievable ? I tried to set the origin and the timezone, > neither of which seems to make a difference. > On my Mac Book Pro (R version 2.9.1) which is set to Eastern US time zone, I > obtain the shifted result: >> as.POSIXct(as.Date("2008-07-01")) > [1] "2008-06-30 20:00:00 EDT" > > And e.g. >> as.POSIXct( Sys.Date()) > [1] "2009-09-17 20:00:00 EDT" >> Sys.time() > [1] "2009-09-18 10:10:48 EDT" > > Any help would make life simpler for me. > > Thanks, > Markus > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >