Why does as.POSIXct fail to parse 12:00 for me as 00:00:00?
> as.POSIXct('11:59 PM',format='%I:%M %p')
[1] "2021-10-31 23:59:00 EDT"
> as.POSIXct('12:00 AM',format='%I:%M %p')
[1] "2021-10-31 EDT"
> as.POSIXct('12:01 AM',format='%I:%M %p')
[1] "2021-10-31 00:01:00 EDT"
CodePudding user response:
It is related to the format
i.e. if we check the ?as.POSIXct
format - character string giving a date-time format as used by strptime.
Therefore, check the ?strptime
format - A character string. The default for the format methods is "%Y-%m-%d %H:%M:%S" if any element has a time component which is not midnight, and "%Y-%m-%d" otherwise. If options("digits.secs") is set, up to the specified number of digits will be printed for seconds.
CodePudding user response:
We could use lubridate
package:
library(lubridate)
hm('12:00 AM')