Strip the date and keep the time

前端 未结 2 468
我在风中等你
我在风中等你 2020-12-30 03:46

Lots of people ask how to strip the time and keep the date, but what about the other way around? Given:

myDateTime <- \"11/02/2014 14:22:45\"


        
相关标签:
2条回答
  • 2020-12-30 04:25

    If the time within a GMT day is useful for your problem, you can get this with %%, the remainder operator, taking the remainder modulo 86400 (the number of seconds in a day).

    stamps <- c("2013-04-12 19:00:00", "2010-04-01 19:00:01", "2018-06-18 19:00:02")
    as.numeric(as.POSIXct(stamps)) %% 86400
    ## [1] 0 1 2
    
    0 讨论(0)
  • 2020-12-30 04:30

    I think you're looking for the format function.

    (x <- strptime(myDateTime, format="%d/%m/%Y %H:%M:%S"))
    #[1] "2014-02-11 14:22:45"
    format(x, "%H:%M:%S")
    #[1] "14:22:45"
    

    That's character, not "time", but would work with something like aggregate if that's what you mean by "analyse events recorded over several days by time of day only."

    0 讨论(0)
提交回复
热议问题