Galkowski, Jan
2009-May-05 18:55 UTC
[R] documenting quirky behavior of as.POSIXct, as.POSIX.lt regarding AM/PM, possibly other cases
I wanted to put this on the R Wiki, but found the suitable pages were read-only. I wanted to get it out in public to save people work. I was converting dates like "2009/03/26 01:00:00 AM" using as.POSIXct. I found that using a format of "%Y/%m/%d %I:%M:%S %p" did not work correctly to distinguish AM from PM. Both were converted into the same timestamp. Indeed, what I found worked was affixing a space after the string timestamp to produce "2009/03/26 01:00:00 AM " or "2009/03/26 01:00:00 PM ". That works. Didn't see this documented in the associated pages anywhere. I wonder if the help system might benefit from user comments like for instance PHP has?
jim holtman
2009-May-05 20:06 UTC
[R] documenting quirky behavior of as.POSIXct, as.POSIX.lt regarding AM/PM, possibly other cases
Seems to work fine for me on R 2.9.0:> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p" )[1] "2009-03-26 01:00:00 GMT"> as.POSIXct("2009/03/26 01:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p" )[1] "2009-03-26 13:00:00 GMT">On Tue, May 5, 2009 at 2:55 PM, Galkowski, Jan <jgalkows@akamai.com> wrote:> > I wanted to put this on the R Wiki, but found the suitable pages were > read-only. I wanted to get it out in public to save people work. > > I was converting dates like "2009/03/26 01:00:00 AM" using as.POSIXct. I > found that using a format of "%Y/%m/%d %I:%M:%S %p" did not work correctly > to distinguish AM from PM. Both were converted into the same timestamp. > Indeed, what I found worked was affixing a space after the string timestamp > to produce "2009/03/26 01:00:00 AM " or "2009/03/26 01:00:00 PM ". That > works. > > Didn't see this documented in the associated pages anywhere. > > I wonder if the help system might benefit from user comments like for > instance PHP has? > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
Reasonably Related Threads
- Standards for delivery of GPL software in CRAN packages
- slight documentation error in "stats" package "arima"
- convex optimization package for R, specifically semidefinite programming
- voronoi/Delaunay/Dirichlet tessellation on sphere in R or S?
- predict "interval" for lmRob?