### Name: strptime ### Title: Date-time Conversion Functions to and from Character ### Aliases: format.POSIXct format.POSIXlt strftime strptime ### as.character.POSIXt ISOdatetime ISOdate ### Keywords: utilities chron ### ** Examples ## locale-specific version of date() format(Sys.time(), "%a %b %d %X %Y %Z") ## time to sub-second accuracy (if supported by the OS) format(Sys.time(), "%H:%M:%OS3") ## read in date info in format 'ddmmmyyyy' ## This will give NA(s) in some locales; setting the C locale ## as in the commented lines will overcome this on most systems. ## 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) strptime(x, "%m/%d/%y %H:%M:%S") ## time with fractional seconds z <- strptime("20/2/06 11:16:16.683", "%d/%m/%y %H:%M:%OS") z # prints without fractional seconds op <- options(digits.secs=3) z options(op) ## timezones are not portable, but 'EST5EDT' comes pretty close. (x <- strptime(c("2006-01-08 10:07:52", "2006-08-07 19:33:02"), "%Y-%m-%d %H:%M:%S", tz="EST5EDT")) attr(x, "tzone")