timeDate
object to a new time zone.
timeZoneConvert(x, zone)
timeDate
object.
Internally, all
timeDate
objects are
stored as times in GMT with an associated
time.zone
slot. Conversion to the
"local" time zone is done only for the purpose of displaying the
timeDate
object.
Modifying the
time.zone
slot directly
alters the time zone of the object, but not the time itself (it
represents the same instant in a different part of the world). When
displayed, the time component will differ according to the time
difference betwwen the time zones before and after the change.
The function
timeZoneConvert
modifies the
time zone and the actual time by the time difference between
the new and old time zones. As a result, the printed display of the
timeDate
object remains the same (other
than any displayed time zone information). This is useful when
reading in data from a file without any specific time zone information
(which by default will be created with a GMT time zone), and then
converting it to a different local time zone without changing the
printed appearance of the dates and times.
options(time.zone="GMT", time.in.format="%m/%d/%Y [%H:%M]", time.out.format="%m/%d/%Y %02H:%02M (%Z)") date1 <- timeDate("3/22/2002 12:00", zone="GMT") date1 # 3/22/2002 12:00 (GMT) date2 <- timeZoneConvert(date1, "PST") date2 # appears the same as date1, except for zone # 3/22/2002 12:00 (PST) date1 - date2 # these times are 8 hours apart # modifying the time.zone slot does not change # the actual time, just the display date3 <- date2 date3@time.zone <- "EST" date3 # displays as 3 hours later # 3/22/2002 15:00 (EST) date2-date3 # but the difference is zero # 0d 0h 0m 0s 0MS