1

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はありませんtzPOSIXlt別のタイムゾーンで日付を出力するには、最初にlubridateパッケージを使用してPOSIXltオブジェクトを目的のタイムゾーンに変換できます。

require(lubridate)
lt.changed = with_tz(lt, tz=to)
format(lt.changed, usetz=TRUE)
#[1] "2015-12-09 05:30:00 PST"
4

0 に答える 0