方便地獲取和設置日期時間的時區。
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。