Get the TimeZone of an
1 2 3 4 5
a valid TZ object
As of version 0.6-4 all objects carry the time zone
under which they were created in a hidden
Going forward from 0.7-4, the TZ variable is now
also stored in the index itself, in the
attribute. This is to facilitate the transition to
removing the xts-specific attributes referenced by
These accessor functions will continue to behave the
same under the new internals. Additionally, there is a new
getter/setter method with
Internally, all time indexing is converted to POSIXct, seconds since the epoch as defined by a combination of the underlying OS and the TZ variable setting at creation. The current implementation of xts manages time zone information as transparently as possible, delegating all management to R, which is in turn managed in most instances by the underlying operating system.
During printing, and subsetting by time strings the internal POSIX representation is used to identify in human-friendly terms the time at each position.
This is different than previous versions of xts, where the index was stored in its native format (i.e. class).
The ability to create an index using any of the supported
timeBased classes (POSIXct, Date, dates, chron, timeDate,
yearmon, yearqtr) is managed at the user-interaction point,
and the class is merely stored in another hidden attribute
.indexCLASS. This is accessible via
In most cases, all of this makes the subsetting by time strings possible, and also allows for consistent and fast manipulation of the series internally.
Problems may arise when an object that had been created under
one TZ (time zone) are used in a session using another TZ. This
isn't usually a issue, but when it is a warning is given upon printing
or subsetting. This warning may be controlled with
A named vector of length one, giving the objects TZ at creation.
Timezones are a difficult issue to manage. If intraday granularity is not needed, it is often best to set the system TZ to "GMT" or "UTC".
Jeffrey A. Ryan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Loading required package: zoo Attaching package: 'zoo' The following objects are masked from 'package:base': as.Date, as.Date.numeric  "UTC"  "UTC" An 'xts' object on 2018-01-16/2018-01-25 containing: Data: int [1:10, 1] 1 2 3 4 5 6 7 8 9 10 Indexed by objects of class: [Date] TZ: UTC xts Attributes: NULL [,1] 2018-01-16 1 2018-01-17 2 2018-01-18 3 2018-01-19 4 2018-01-20 5 2018-01-21 6 2018-01-22 7 2018-01-23 8 2018-01-24 9 2018-01-25 10 [,1] 2018-01-16 1 2018-01-17 2 2018-01-18 3 2018-01-19 4 2018-01-20 5 2018-01-21 6 2018-01-22 7 2018-01-23 8 2018-01-24 9 2018-01-25 10
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.