Consider the following R console output.
> Sys.getlocale()
[1] "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C"
> dh <- '2018-05-08 07:42:34 PM'
> as.POSIXlt(dh,'%Y-%m-%d %I:%M:%S %p')
[1] "2018-05-08 07:42:34"
> strptime(dh,'%Y-%m-%d %I:%M:%S %p')
[1] "2018-05-08 19:42:34 -03"
If both formats are identical, why doesn't as.POSIXlt
recognize the 12-hour format properly? dh
gives a time at night (7 PM), but the function is returning a time in the morning! as.POSIXct
gives the same error.
What am I missing here?