这是因为您直接操作列表的元素(POSIXlt 对象)。打印时,它被规范化为“真实”日期,但是当访问单个元素时,它们仍然具有非规范化值。
考虑
d
dput(d)
d$mon <- d$mon + 12
dput(d)
d <- as.POSIXlt(as.POSIXct(d))
dput(d)
给了
> d <- as.POSIXlt("1900-01-01")
> dput(d)
structure(list(sec = 0, min = 0L, hour = 0L, mday = 1L, mon = 0L,
year = 0L, wday = 1L, yday = 0L, isdst = 0L), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt"))
> d$mon <- d$mon + 12
> dput(d)
structure(list(sec = 0, min = 0L, hour = 0L, mday = 1L, mon = 12,
year = 0L, wday = 1L, yday = 0L, isdst = 0L), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt"))
> d <- as.POSIXlt(as.POSIXct(d))
> dput(d)
structure(list(sec = 0, min = 0L, hour = 0L, mday = 1L, mon = 0L,
year = 1L, wday = 2L, yday = 0L, isdst = 0L), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt"), tzone = c("", "PST", "PDT"
))
请注意,强制转换为 POSIXct 并返回到 POSIXlt 对其进行了规范化(年为 1,周一为 0)