The function Sys.time()
outputs the date and time in a
format like this: 2022-06-24 11:25:10. You can choose the format for
date or time by wrapping the Sys.time()
function inside the
format
function, with a second argument that determines the
format of the output. The second argument is a string comprised of a
percent symbol followed by a letter. The full list of formats that are
outputted for each letter are shown below. Note that you can combine
formats in a single format
function, for example
format(Sys.time(), "%A %B %d, %G"
produces “Friday June 24,
2022”.
The output for Sys.Date()
is the same except that the
time is always midnight.
## [1] "format(Sys.time(), '%a') - Fri"
## [1] "format(Sys.time(), '%A') - Friday"
## [1] "format(Sys.time(), '%b') - Jun"
## [1] "format(Sys.time(), '%B') - June"
## [1] "format(Sys.time(), '%c') - Fri Jun 24 11:25:10 2022"
## [1] "format(Sys.time(), '%C') - 20"
## [1] "format(Sys.time(), '%d') - 24"
## [1] "format(Sys.time(), '%D') - 06/24/22"
## [1] "format(Sys.time(), '%e') - 24"
## [1] "format(Sys.time(), '%E') - E"
## [1] "format(Sys.time(), '%f') - f"
## [1] "format(Sys.time(), '%F') - 2022-06-24"
## [1] "format(Sys.time(), '%g') - 22"
## [1] "format(Sys.time(), '%G') - 2022"
## [1] "format(Sys.time(), '%h') - Jun"
## [1] "format(Sys.time(), '%H') - 11"
## [1] "format(Sys.time(), '%i') - i"
## [1] "format(Sys.time(), '%I') - 11"
## [1] "format(Sys.time(), '%j') - 175"
## [1] "format(Sys.time(), '%J') - J"
## [1] "format(Sys.time(), '%k') - 11"
## [1] "format(Sys.time(), '%K') - K"
## [1] "format(Sys.time(), '%l') - 11"
## [1] "format(Sys.time(), '%L') - L"
## [1] "format(Sys.time(), '%m') - 06"
## [1] "format(Sys.time(), '%M') - 25"
## [1] "format(Sys.time(), '%n') - \n"
## [1] "format(Sys.time(), '%N') - N"
## [1] "format(Sys.time(), '%o') - o"
## [1] "format(Sys.time(), '%O') - O"
## [1] "format(Sys.time(), '%p') - am"
## [1] "format(Sys.time(), '%P') - am"
## [1] "format(Sys.time(), '%q') - q"
## [1] "format(Sys.time(), '%Q') - Q"
## [1] "format(Sys.time(), '%r') - 11:25:10 am"
## [1] "format(Sys.time(), '%R') - 11:25"
## [1] "format(Sys.time(), '%s') - 1656066310"
## [1] "format(Sys.time(), '%S') - 10"
## [1] "format(Sys.time(), '%t') - \t"
## [1] "format(Sys.time(), '%T') - 11:25:10"
## [1] "format(Sys.time(), '%u') - 5"
## [1] "format(Sys.time(), '%U') - 25"
## [1] "format(Sys.time(), '%v') - 24-Jun-2022"
## [1] "format(Sys.time(), '%V') - 25"
## [1] "format(Sys.time(), '%w') - 5"
## [1] "format(Sys.time(), '%W') - 25"
## [1] "format(Sys.time(), '%x') - 24 Jun 2022"
## [1] "format(Sys.time(), '%X') - 11:25:10"
## [1] "format(Sys.time(), '%y') - 22"
## [1] "format(Sys.time(), '%Y') - 2022"
## [1] "format(Sys.time(), '%z') - +0100"
## [1] "format(Sys.time(), '%Z') - BST"