How to Apply tz() Function of lubridate Package in R (2 Examples)
This article shows how to apply the tz function of the lubridate package in R.
Preparing the Examples
x <- as.POSIXlt("2023-11-23 08:37:11") # Date & time object x # [1] "2023-11-23 08:37:11 UTC" |
x <- as.POSIXlt("2023-11-23 08:37:11") # Date & time object x # [1] "2023-11-23 08:37:11 UTC"
install.packages("lubridate") # Install lubridate package library("lubridate") # Load lubridate package |
install.packages("lubridate") # Install lubridate package library("lubridate") # Load lubridate package
Example 1: Setting Time Zone of Date Object Using tz() Function of lubridate Package
tz(x) <- "Etc/GMT" # Change time zone x # [1] "2023-11-23 08:37:11 UTC" |
tz(x) <- "Etc/GMT" # Change time zone x # [1] "2023-11-23 08:37:11 UTC"
Example 2: Returning Time Zone of Date Object Using tz() Function of lubridate Package
tz(x) # Query time zone # "Etc/GMT" |
tz(x) # Query time zone # "Etc/GMT"