我无法让 RPOSIXlt
在所需的时区格式化对象。POSIXct
按预期工作。这是一个错误还是我错过了什么?
date.str = "2015-12-09 13:30"
from = "Europe/London"
to = "America/Los_Angeles"
lt = as.POSIXlt(date.str, tz=from)
format(lt, tz=to, usetz=TRUE)
#[1] "2015-12-09 13:30:00 GMT"
ct = as.POSIXct(date.str, tz=from)
format(ct, tz=to, usetz=TRUE)
#[1] "2015-12-09 05:30:00 PST"
tzone
属性是一样的:
attributes(ct)$tzone
#[1] "Europe/London"
attributes(lt)$tzone
#[1] "Europe/London"
解决方案
正如@nicola 所指出的,format.POSIXlt
没有tz
参数。POSIXlt
要在另一个时区打印日期,可以先使用lubridate
包将POSIXlt
对象转换为所需的时区:
require(lubridate)
lt.changed = with_tz(lt, tz=to)
format(lt.changed, usetz=TRUE)
#[1] "2015-12-09 05:30:00 PST"