方便地获取和设置日期时间的时区。
tz<-
是 force_tz()
的别名,它保留本地时间,创建不同的时间点。如果您想保持瞬间相同,但更改打印表示,请使用with_tz()
。
有效时区
时区存储在系统特定的数据库中,因此不能保证每个系统上的时区都相同(但是,它们通常非常相似,除非您的系统非常过时)。您可以使用 OlsonNames()
查看完整列表。
也可以看看
有关底层 tzone
属性的说明,请参阅DateTimeClasses。
例子
x <- y <- ymd_hms("2012-03-26 10:10:00", tz = "UTC")
tz(x)
#> [1] "UTC"
# Note that setting tz() preserved the clock time, which implies
# that the actual instant in time is changing
tz(y) <- "Pacific/Auckland"
y
#> [1] "2012-03-26 10:10:00 NZDT"
x - y
#> Time difference of 13 hours
# This is the same as force_tz()
force_tz(x, "Pacific/Auckland")
#> [1] "2012-03-26 10:10:00 NZDT"
# Use with_tz() if you want to change the time zone, leave
# the instant in time the same
with_tz(x, "Pacific/Auckland")
#> [1] "2012-03-26 23:10:00 NZDT"
相关用法
- R lubridate time_length 计算时间跨度的准确长度
- R lubridate DateTimeUpdate 更改日期对象的组成部分
- R lubridate stamp 基于人性化模板设置日期和时间格式
- R lubridate interval 用于创建和操作 Interval 对象的实用程序
- R lubridate is.difftime x 是 difftime 对象吗?
- R lubridate as_date 将对象转换为日期或日期时间
- R lubridate date 获取/设置日期时间的日期部分
- R lubridate round_date 日期时间对象的舍入、取整和取整方法
- R lubridate make_difftime 创建一个 difftime 对象。
- R lubridate is.timespan x 是时间长度吗?
- R lubridate with_tz 获取不同时区的日期时间
- R lubridate mplus 在日期中添加和减去月份,但不超过新月份的最后一天
- R lubridate cyclic_encoding 日期时间的循环编码
- R lubridate as.interval 将对象更改为间隔
- R lubridate second 获取/设置日期时间的秒部分
- R lubridate quarter 获取日期时间的财政季度和学期
- R lubridate posix_utils 各种 POSIX 实用程序
- R lubridate date_decimal 将小数转换为日期
- R lubridate as.duration 将对象更改为持续时间
- R lubridate hour 获取/设置日期时间的小时部分
- R lubridate minute 获取/设置日期时间的分钟部分
- R lubridate month 获取/设置日期时间的月份部分
- R lubridate duration 创建一个持续时间对象。
- R lubridate leap_year 一年是闰年吗?
- R lubridate local_time 从日期时间向量获取当地时间。
注:本文由纯净天空筛选整理自Hadley Wickham等大神的英文原创作品 Get/set time zone component of a date-time。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。