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-%m-%d")
d
[1] "2014-07-08"
as.POSIXct(d)
[1] "2014-07-07 21:00:00 BRT"
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-%m-%d")
d
[1] "2014-07-08"
as.POSIXct(d)
[1] "2014-07-07 21:00:00 BRT"
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"
character
first: as.POSIXct(format(d))
–
Rufford (...)
argument but it is not passed to .POSIXct
, and passing a simple timezone paramater would solve this .POSIXct(unclass(d) * 86400, tz="UTC")
–
Oviposit © 2022 - 2024 — McMap. All rights reserved.
as.POSIXct(d, tz = "...")
? – Banky?as.POSIXct
): "Dates without times are treated as being at midnight UTC." – Banky