POSIXlt
目的のタイムゾーンでオブジェクトをフォーマットする R を取得できません。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"