简体   繁体   中英

Converting 12 hour format to 24 hour without timezone in R

I've tried using strptime and as.Date to convert a 12 hour format to 24 hour but I'm getting NA for both. I'm not sure where the issue is

as.Date("3/23/2017 3:10:36 PM", format="%m/%d/%y  %I:%M:%S %p")
strptime("3/23/2017 3:10:36 PM","%m/%d/%y %I:%M:%S %p")

Any pointers to help me out? Preferably without a timezone appended

Simply use

x <- strptime("3/23/2017 3:10:36 PM", format="%m/%d/%Y %I:%M:%S %p")

(With capital %Y for 4-digit year) And then

format(x, "%Y-%m-%d %H:%M:%S")

To get a 24-h format character string without time zone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM