strptime() with %p option in non-US locale

The option %p of the hour format for strptime() function requires that locale is set to US:

> Sys.getlocale(category = "LC_TIME")
[1] "fr_FR.UTF-8"
> strptime("2004-01-17 12:49 AM", format="%Y-%m-%d %I:%M %p")
[1] NA
> Sys.setlocale(category = "LC_TIME", locale = "en_US.UTF-8" )
[1] "en_US.UTF-8"
> strptime("2004-01-17 12:49 AM", format="%Y-%m-%d %I:%M %p")

[1] "2004-01-17 00:49:00"

If your system does not allow to use "en_US.UTF-8", just indicate "C"

Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

stepAIC from package MASS with AICc

Install treemix in ubuntu 20.04