这怎么不是bug?
as.POSIXct(as.Date("2013/01/01"))
结果:
[1] "2012-12-31 19:00:00 EST"
它调用as.POSIXct.Date
方法,即
function (x, ...)
.POSIXct(unclass(x) * 86400)
.POSIXct
请注意,尽管有这样的参数,但不可能将时区传递给:
function (xx, tz = NULL)
structure(xx, class = c("POSIXct", "POSIXt"), tzone = tz)
所以会发生这种情况:
structure(unclass(as.Date("2013/01/01")) * 86400,
class = c("POSIXct", "POSIXt"), tzone = "EST")
#[1] "2012-12-31 19:00:00 EST"
如果要转换Date
s 的解决方法:
structure(unclass(as.Date("2013/01/01")) * 86400,
class = c("POSIXct", "POSIXt"), tzone = "GMT")
#"2013-01-01 GMT"
或者修改as.POSIXct.Date
为
function (x, tz=NULL,...) .POSIXct(unclass(x) * 86400, tz = tz)