format.Date
Date-Time Formatting

Description

Functions for converting Date, POSIXt, or difftime objects to character strings.

Usage

## S3 method for class 'Date':
format(x, ...)
## S3 method for class 'Date':
as.character(x, ...)

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

## S3 method for class 'difftime': format(x, ...)

strftime(x, format = "", tz = "", usetz = FALSE, ...)

Arguments

x a Date, POSIXt, or difftime object.
format a character vector specifying the output format.
tz a character string specifying the time zone.
usetz a logical value specifying if time zone should be appended to the output.
... additional arguments.

Details

TIBCO Enterprise Runtime for R uses the current "LC_TIME" locale (see Sys.setlocale) when parsing or writing dates, to determine the appropriate words for the days of the weeks and the months.
Value
format.Date, as.character.Date returns a character vector representing the Date object.
format.POSIXct, format.POSIXlt, as.character.POSIXt returns a character vector representing the POSIXt object.
format.difftime returns a character vector representing the difftime object.
strftime returns a character vector representing the Date or POSIXt object.
References
http://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#Formatting-Calendar-Time.
See Also
Date, POSIXt, difftime, as.Date, format, Sys.setlocale
Examples
## format Date objects
x <- c("1970-01-01 00:00:00", "2038-01-19 03:14:07.123")
(d <- as.Date(x))
format(d)
format(d, format = "%m/%d/%Y", usetz = TRUE)

## format POSIXt objects (pct <- as.POSIXct(x)) format(pct) format(pct, tz = "Asia/Shanghai") format(pct, format = "%Y-%m-%d %H:%M:%OS3", usetz = TRUE) format(pct, format = "%a %b %d %H:%M:%S %Y") # compare with date()

## format Date or POSIXt objects strftime(d, format = "%m/%d/%Y", usetz = TRUE) strftime(pct, format = "%Y-%m-%d %H:%M:%OS3", tz = "Asia/Shanghai", usetz = TRUE)

## reformat date-time strings strftime(x, format = "%a %b %d %H:%M:%S %Y", usetz = TRUE) strftime(x, format = "%a %b %d %H:%M:%S %Y", tz = "Asia/Shanghai", usetz = TRUE)

## option "digits.secs" for millisecond formatting getOption("digits.secs") format(pct) ds.old <- options(digits.secs = 5) format(pct) options(ds.old)

## format difftime objects (dt <- as.difftime(c("0:0:1", "0:1:0", "1:0:0"))) format(dt)

Package base version 6.0.0-69
Package Index