strptime                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 _t_o _a_n_d _f_r_o_m _C_h_a_r_a_c_t_e_r

_D_e_s_c_r_i_p_t_i_o_n:

     Functions to convert between character representations and objects
     of classes `"POSIXlt"' and `"POSIXct"' representing calendar dates
     and times.

_U_s_a_g_e:

     format.POSIXct(x, format = "", tz = "", usetz = FALSE, ...)
     format.POSIXlt(x, format = "", usetz = FALSE, ...)

     as.character.POSIXct(x, ...)
     as.character.POSIXlt(x, ...)

     strftime(x, format="%Y-%m-%d %X", usetz = FALSE, ...)
     strptime(x, format)

     ISOdatetime(year, month, day, hour, min, sec, tz = "")
     ISOdate(year, month, day, hour = 12, min = 0, sec = 0, tz = "GMT")

_D_e_t_a_i_l_s:

     `strftime' is an alias for `format.POSIXlt', and `format.POSIXct'
     first converts to class `"POSIXct"' by calling `as.POSIXct'. Note
     that only that conversion depends on the time zone.

     The usual vector re-cycling rules are applied to `x' and `format'
     so the answer will be of length that of the longer of the vectors.

     Locale-specific conversions to and from character strings are used
     where appropriate and available.  This affects the names of the
     days and months, the AM/PM indicator (if used) and the separators
     in formats such as `%x' and `%X'.

     The details of the formats are system-specific, but the following
     are defined by the POSIX standard for `strftime' and are likely to
     be widely available.  Any character in the format string other
     than the `%' escapes is interpreted literally (and `%%' gives
     `%').

     `%_a' Abbreviated weekday name.

     `%_A' Full weekday name.

     `%_b' Abbreviated month name.

     `%_B' Full month name.

     `%_c' Date and time, locale-specific.

     `%_d' Day of the month as decimal number (01-31).

     `%_H' Hours as decimal number (00-23).

     `%_I' Hours as decimal number (01-12).

     `%_j' Day of year as decimal number (001-366).

     `%_m' Month as decimal number (01-12).

     `%_M' Minute as decimal number (00-59).

     `%_p' AM/PM indicator in the locale.

     `%_S' Second as decimal number (00-61), allowing for up to two
          leap-seconds.

     `%_U' Week of the year as decimal number (00-53) using the first
          Sunday as day 1 of week 1.

     `%_w' Weekday as decimal number (0-6, Sunday is 0).

     `%_W' Week of the year as decimal number (00-53) using the first
          Monday as day 1 of week 1.

     `%_x' Date, locale-specific.

     `%_X' Time, locale-specific.

     `%_y' Year without century (00-99). If you use this on input, which
          century you get is system-specific.  So don't!  Often values
          up to 69 are prefixed by 20 and 70-99 by 19.

     `%_Y' Year with century.

     `%_Z' (output only.) Time zone as a character string (empty if not
          available).  Note: do not use this on Linux unless the `TZ'
          environment variable is set.

     Where leading zeros are shown they will be used on output but are
     optional on input.

     `ISOdatetime' and `ISOdate' are convenience wrappers for
     `strptime', that differ only in their defaults.

_V_a_l_u_e:

     The `format' methods and `strftime' return character vectors
     representing the time.

     `strptime' turns character representations into an object of class
     `"POSIXlt"'.

     `ISOdatetime' and `ISOdate' return an object of class `"POSIXct"'.

_N_o_t_e:

     The default formats follow the rules of the ISO 8601 international
     standard which expresses a day as `"2001-02-03"' and a time as
     `"14:01:02"' using leading zeroes as here.  The ISO form uses no
     space to separate dates and times.

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

     OS facilities will probably not print years before 1CE (aka 1AD)
     correctly.

_R_e_f_e_r_e_n_c_e_s:

     International Organization for Standardization (1988, 1997, ...)
     ISO 8601. Data elements and interchange formats - Information
     interchange - Representation of dates and times. The 1997 version
     is available on-line at <URL:
     ftp://ftp.qsl.net/pub/g1smd/8601v03.pdf>

_S_e_e _A_l_s_o:

     DateTimeClasses for details of the date-time classes; `locales' to
     query or set a locale.

     Your system's help pages on `strftime' and `strptime' to see how
     to specify their formats.

_E_x_a_m_p_l_e_s:

     ## locale-specific version of date()
     format(Sys.time(), "%a %b %d %X %Y")
     ## we would include the timezone as in
     ## format(Sys.time(), "%a %b %d %X %Y %Z")
     ## but this crashes some Linux systems

     ## read in date info in format `ddmmmyyyy'
     ## This will give NA(s) in some locales.
     ## lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
     x <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960")
     z <- strptime(x, "%d%b%Y")
     ## Sys.setlocale("LC_TIME", lct)
     z

     ## read in date/time info in format `m/d/y h:m:s'
     dates <- c("02/27/92", "02/27/92", "01/14/92",
                "02/28/92", "02/01/92")
     times <- c("23:03:20", "22:29:56", "01:03:30",
                "18:21:03", "16:56:26")
     x <- paste(dates, times)
     z <- strptime(x, "%m/%d/%y %H:%M:%S")
     z

