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"
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"

Example 2: Returning Time Zone of Date Object Using tz() Function of lubridate Package

tz(x)                                     # Query time zone
# "Etc/GMT"

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top