Convert military time to standard time with hours and minutes in R

后端 未结 2 1290
离开以前
离开以前 2021-01-15 20:30

I have the following set of times data, that I have to convert into 12 hour format.

-----------------
814
830
1835
1730
1442
820
1430
930
1550
1725
1615
1010         


        
2条回答
  •  抹茶落季
    2021-01-15 21:01

    You can try,

    format(strptime(substr(as.POSIXct(sprintf("%04.0f", x), 
                                     format="%H%M"), 12, 16), '%H:%M'), '%I:%M %p')
    
    #[1] "08:14 AM" "08:30 AM" "06:35 PM" "05:30 PM" "02:42 PM" "08:20 AM"
    

    data

    x <- c(814, 830, 1835, 1730,1442, 820)
    

提交回复
热议问题