as.POSIXct,时区部分被忽略

问题描述 投票:0回答:1

这是我的例子。

test <- as.POSIXct(as.Date("2019-11-01"), tz = "UTC")
test

它打印:

[1] "2019-10-31 19:00:00 CDT"

它似乎忽略了tz参数:

attr(test, "tzone")

返回NULL。

为什么会有“ 19”小时而不是00小时?如何将其设置为00小时并取UTC

r posixct
1个回答
0
投票

我们可以使用with_tz中的lubridate

library(lubridate)
test1 <- with_tz(as.Date("2019-11-01"), tzone = 'UTC')
attr(test1, 'tzone')
#[1] "UTC"
© www.soinside.com 2019 - 2024. All rights reserved.