DateTimeClasses             package:base             R Documentation

_D_a_t_e-_T_i_m_e _C_l_a_s_s_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Description of the classes `"POSIXlt"' and `"POSIXct"'
     representing calendar dates and times (to the nearest second).

_U_s_a_g_e:

     print.POSIXct(x, ...)
     print.POSIXlt(x, ...)

     summary.POSIXct(object, digits = 15, ...)
     summary.POSIXlt(object, digits = 15, ...)

     time + number
     time - number
     time1 lop time2

     c(time1, ...)
     mean(time)

_A_r_g_u_m_e_n_t_s:

x, object: An object to be printed or summarized.

  digits: Number of significant digits for the computations: should be
          high enough to represent the least important time unit
          exactly.

     ...: Further arguments to be passed from or to other methods.

time, time1, time2, ...: date-time objects.

  number: a numeric object.

     lop: One of `==', `!=', `<', `<=', `>' or `>='.

_D_e_t_a_i_l_s:

     There are two basic classes of date/times.  Class `"POSIXct"'
     represents the (signed) number of seconds since the beginning of
     1970 as a numeric vector.  Class `"POSIXlt"' is a named list of
     vectors representing

     `_s_e_c' 0-61: seconds

     `_m_i_n' 0-59: minutes

     `_h_o_u_r' 0-23: hours

     `_m_d_a_y' 1-31: day of the month

     `_m_o_n' 0-11: months after the first of the year.

     `_y_e_a_r' Years since 1900.

     `_w_d_a_y' 0-6 day of the week, starting on Sunday.

     `_y_d_a_y' 0-365: day of the year.

     `_i_s_d_s_t' Daylight savings time flag. Positive if in force, zero if
          not, negative if unknown.

     The classes correspond to the ANSI C constructs of ``calendar
     time'' (the `time_t' data type) and ``local time'' (or broken-down
     time, the `struct tm' data type), from which they also inherit
     their names.

     `"POSIXct"' is more convenient for including in data frames, and
     `"POSIXlt"' is closer to human-readable forms.  Logical
     comparisons and limited arithmetic are available for both classes.
     Differences between objects are returned as the number of
     (non-leap) seconds between them.  One can add or subtract a number
     of seconds from a date-time object, but not add two date-time
     objects.

     `"POSIXlt"' objects will often have an attribute `"tzone"', a
     character vector of length 3 giving the timezone name from the
     `"TZ"' environment variable and the names of the base timezone and
     the alternate (daylight-saving) timezone.  Sometimes this may just
     be of length one, giving the timezone name.

     Unfortunately, the conversion is complicated by the operation of
     time zones and leap seconds (22 days have been 86401 seconds long
     so far: the times of the extra seconds are in the object
     `.leap.seconds'). The details of this are entrusted to the OS
     services where possible. This will usually cover the period
     1970-2037, and on Unix machines back to 1902 (when time zones were
     in their infancy).  Outside those ranges we use our own C code. 
     This uses the offset from GMT in use in the timezone in 2000, and
     uses the alternate (daylight-saving) timezone only if `isdst' is
     positive.

     It seems that some systems use leap seconds but most do not. This
     is detected and corrected for at build time, so all `"POSIXct"'
     times used by R do not include leap seconds.  (Conceivably this
     could be wrong if the system has changed since build time, just
     possibly by changing locales.)

     Using `c' on `"POSIXlt"' objects converts them to the current time
     zone.

_W_a_r_n_i_n_g:

     Some Unix-like systems (especially Linux ones) do not have `"TZ"'
     set, yet have internal code that expects it (as does POSIX).  We
     have tried to work around this, but if you get unexpected results
     try setting `"TZ"'.

_S_e_e _A_l_s_o:

     `as.POSIXct' and `as.POSIXlt' for conversion between the classes.

     `strptime' for conversion to and from character representations.

     `Sys.time' for clock time as a `"POSIXct"' object.

_E_x_a_m_p_l_e_s:

     (z <- Sys.time())             # the current date, as class "POSIXct"

     (z <- Sys.time() - 3600)      # an hour ago
     Sys.time() - z                # just over 3600 seconds.

     as.POSIXlt(Sys.time(), "GMT") # the current time in GMT
     format(.leap.seconds)         # all 22 leapseconds in your timezone

