Extract time from datatime in R

前端 未结 1 681
抹茶落季
抹茶落季 2021-01-27 12:43

I have \"datetimes\" like this:

02FEB2015:00:06:00.000000

and need to extract the time as:

06:00

Tried:

相关标签:
1条回答
  • 2021-01-27 13:42

    When converting character to POSIXlt class, you need to specify exactly the same format as how the character is formulated. You can use normal strptime and format functions, an example:

    As commented by @Zheyuan but slightly different:

    format(strptime('02FEB2015:00:06:00.000000', "%d%b%Y:%H:%M:%S"), "%M:%S")
    # [1] "06:00"
    
    0 讨论(0)
提交回复
热议问题