R as.POSIXct parsing error

后端 未结 1 1370
难免孤独
难免孤独 2020-12-04 02:41

I am trying to parse a vector of time string and came across a strange error. For example, if I run the following section of code, R returned the result as expected.

相关标签:
1条回答
  • 2020-12-04 03:16

    You cannot parse non-existing times. 02:00:10 did not exist as we had 'spring forward' this Saturday night / Sunday morning with the switch to daylight-savings. R knows this:

    R> t_1 = "03/13/2011 01:00:10"; as.POSIXct(t_1, format = time_format)
    [1] "2011-03-13 01:00:10 CST"
    R> t_2 = "03/13/2011 02:00:10"; as.POSIXct(t_2, format = time_format)
    [1] "2011-03-13 01:00:10 CST"
    R> t_3 = "03/13/2011 03:00:10"; as.POSIXct(t_3, format = time_format)
    [1] "2011-03-13 03:00:10 CDT"
    R> 
    

    On Linux, my timezone library seems to cope -- 02:00:10 becomes 01:00:10 as an hour is subtracted.

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