Parse timestamp with a.m./p.m

前端 未结 2 1304
星月不相逢
星月不相逢 2021-02-20 03:17

I have a file that formats time stamps like 25/03/2011 9:15:00 p.m.

How can I parse this text to a Date-Time class with either strptime or as.POSIXct?

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 03:37

    Just came across this, as another option you can use stringr package.

    library(stringr)
    data$date2 <- str_sub(data$date, end = -4) 
    # this removes the punctuation but holds onto the A/P values
    data$date2 <- str_c(data$date2, 'm') 
    # adds the required m
    

提交回复
热议问题