as.POSIX*                package:base                R Documentation

_D_a_t_e-_t_i_m_e _C_o_n_v_e_r_s_i_o_n _F_u_n_c_t_i_o_n_s

_D_e_s_c_r_i_p_t_i_o_n:

     Functions to manipulate objects of classes '"POSIXlt"' and
     '"POSIXct"' representing calendar dates and times.

_U_s_a_g_e:

     as.POSIXct(x, tz = "", ...)
     as.POSIXlt(x, tz = "", ...)

     ## S3 method for class 'character':
     as.POSIXlt(x, tz = "", format, ...)

     ## S3 method for class 'numeric':
     as.POSIXlt(x, tz = "", origin, ...)

     ## S3 method for class 'POSIXlt':
     as.double(x, ...)

_A_r_g_u_m_e_n_t_s:

       x: An object to be converted.

      tz: A timezone specification to be used for the conversion, _if
          one is required_.  System-specific (see time zones), but '""'
          is the current timezone, and '"GMT"' is UTC (Universal Time,
          Coordinated).

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

  format: character string giving a date-time format as used by
          'strptime'.

  origin: a date-time object, or something which can be coerced by
          'as.POSIXct(tz="GMT")' to such an object.

_D_e_t_a_i_l_s:

     The 'as.POSIX*' functions convert an object to one of the two
     classes used to represent date/times (calendar dates plus time to
     the nearest second).  They can convert a wide variety of objects,
     including objects of the other class and of classes '"Date"',
     '"date"' (from package 'date' or 'survival'), '"chron"' and
     '"dates"' (from package 'chron') to these classes.  Dates without
     times are treated as being at midnight UTC.

     They can also convert character strings of the formats
     '"2001-02-03"' and '"2001/02/03"' optionally followed by white
     space and a time in the format '"14:52"' or '"14:52:03"'. 
     (Formats such as '"01/02/03"' are ambiguous but can be converted
     via a format specification by 'strptime'.)  Fractional seconds are
     allowed. Alternatively, 'format' can be specified for character
     vectors or factors.

     Logical 'NA's can be converted to either of the classes, but no
     other logical vectors can be.

     The 'as.double' method converts '"POSIXlt"' objects to
     '"POSIXct"'.

     If you are given a numeric time as the number of seconds since an
     epoch, see the examples.

_V_a_l_u_e:

     'as.POSIXct' and 'as.POSIXlt' return an object of the appropriate
     class.  If 'tz' was specified, 'as.POSIXlt' will give an
     appropriate '"tzone"' attribute.

_N_o_t_e:

     If you want to extract specific aspects of a time (such as the day
     of the week) just convert it to class '"POSIXlt"' and extract the
     relevant component(s) of the list, or if you want a character
     representation (such as a named day of the week) use
     'format.POSIXlt' or 'format.POSIXct'.

     If a timezone is needed and that specified is invalid on your
     system, what happens is system-specific but it will probably be
     ignored.

_S_e_e _A_l_s_o:

     DateTimeClasses for details of the classes; 'strptime' for
     conversion to and from character representations. 'Sys.timezone'
     for details of the (system-specific)naming of time zones.

_E_x_a_m_p_l_e_s:

     (z <- Sys.time())             # the current datetime, as class "POSIXct"
     unclass(z)                    # a large integer
     floor(unclass(z)/86400)       # the number of days since 1970-01-01
     (z <- as.POSIXlt(Sys.time())) # the current datetime, as class "POSIXlt"
     unlist(unclass(z))            # a list shown as a named vector

     ## suppose we have a time in seconds since 1960-01-01 00:00:00 GMT
     z <- 1472562988
     # ways to convert this
     as.POSIXct(z, origin="1960-01-01")                # local
     as.POSIXct(z, origin="1960-01-01", tz="GMT")      # in UTC
     as.POSIXct(z, origin=ISOdatetime(1960,1,1,0,0,0)) # local
     ISOdatetime(1960,1,1,0,0,0) + z                   # local

     ## SPSS dates (R-help 2006-02-17)
     z <- c(10485849600, 10477641600, 10561104000, 10562745600)
     as.Date(as.POSIXct(z, origin="1582-10-14", tz="GMT"))

     as.POSIXlt(Sys.time(), "GMT") # the current time in UTC
     ## Not run: 
     ## These may not be correct names on your system
     as.POSIXlt(Sys.time(), "America/New_York")  # in New York
     as.POSIXlt(Sys.time(), "EST5EDT")           # alternative.
     as.POSIXlt(Sys.time(), "EST" )   # somewhere in Eastern Canada
     as.POSIXlt(Sys.time(), "HST")    # in Hawaii
     as.POSIXlt(Sys.time(), "Australia/Darwin")
     ## End(Not run)

