[R] Bug in as.POSIXct regarding AM/PM
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Oct 8 15:37:09 CEST 2010
On Fri, Oct 8, 2010 at 5:54 AM, Ted Zeng (曾振兴) <zengzhenxing at gmail.com> wrote:
>
> Dear All,
>
> I encounted in a problem with as.POSIXct() function.
>
>> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>> as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>
> I have tried this in the R version 2.11.1, R version 2.10.1 and R version
> 2.9.2 . They all does not work. The operation system is win7.
I can reproduce this on Windows Vista if I set the locale of LC_Time
to Chinese. If its set to English then it works ok:
> Sys.setlocale("LC_TIME", "Chinese")
[1] "Chinese (Simplified)_People's Republic of China.936"
>
> Sys.getlocale("LC_TIME")
[1] "Chinese (Simplified)_People's Republic of China.936"
>
> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
[1] NA
>
>
> Sys.setlocale("LC_TIME", "English")
[1] "English_United States.1252"
>
> Sys.getlocale("LC_TIME") # check it
[1] "English_United States.1252"
>
> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 01:00:00 EDT"
>
>
> R.version.string
[1] "R version 2.11.1 Patched (2010-05-31 r52167)"
> win.version()
[1] "Windows Vista (build 6002) Service Pack 2"
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list