Convert Date to POSIXct

前端 未结 1 1873
无人及你
无人及你 2020-12-18 22:50

Why does the Date below change to \"2014-07-07\" when converted to POSIXct?

Sys.setenv(TZ=\'America/Sao_Paulo\')
d <- as.Date(\"2014-07-08\", format=\"%Y-         


        
相关标签:
1条回答
  • 2020-12-18 22:54

    Because as.POSIXct.Date doesn't look for a timezone (and won't pass it to .POSIXct if you specify it in ...) and Date objects are "UTC", so your POSIXct is offset from the UTC of the Date object.

    It would be better to call as.POSIXct on the character string directly, if you can:

    > as.POSIXct("2014-07-08", format="%Y-%m-%d")
    [1] "2014-07-08 BRT"
    
    0 讨论(0)
提交回复
热议问题