Reputation: 355
I need to get current time in R in this particular format:
2014-01-07T14:57:55+05:30
Sys.time()
seems to return in a different format than this. How do I exactly get this ?
Link to the format : https://en.wikipedia.org/wiki/ISO_8601
Upvotes: 1
Views: 1315
Reputation: 1664
Is this what your looking for?
format(Sys.time(), format="%Y-%m-%dT%H:%M:%S+01:00")
format(Sys.time(), format="%Y-%m-%dT%H:%M:%S%z")
The meaning of the letters you find a the documentation of strptime()
function
Upvotes: 1
Reputation: 1157
The function for converting/formatting a time string is as.POSIXct
or as.POSIXlt
. The documentation for these points to the docs for strptime for format symbols. This reference indicates %F
is the correct symbol for ISO-8601
however, implementing that results in a format different from what you suggest.
> as.POSIXct(Sys.time(),format="%F")
[1] "2016-10-02 18:57:58 EDT"
I suspect looking at strptime you will find the combination necessary to output the exact format you need.
Upvotes: 2