How to use and format time and date information in R.

Table of Contents

ISO 8601 Format

Reading time:

as.POSIXlt(Sys.time(), "UTC", "%Y-%m-%dT%H:%M:%S")
  ## [1] "2018-12-11 16:31:25 UTC"
as.POSIXlt(Sys.time(), "Asia/Baghdad", "%Y-%m-%dT%H:%M:%S")
  ## [1] "2018-12-11 19:31:26 +03"

Writing time:

tm = as.POSIXlt(Sys.time(), "Asia/Baghdad", "%Y-%m-%dT%H:%M:%S")
strftime(tm , "%Y-%m-%dT%H:%M:%S%z")
  ## [1] "2018-12-11T19:31:26+0300"
strftime(Sys.time(), "%Y-%m-%dT%H:%M:%S%z")
  ## [1] "2018-12-11T19:31:26+0300"