An argument for an API requires me to format time as YYYYMMDDHHMM, i.e. 3 March 2019 14:30 would be "201903031430". I'm trying to do some operations beforehand and then convert the result into that string format, but I haven't come up with anything succinct. For example, using lubridate
:
library(lubridate)
paste0(year(now()),month(now()),day(now()),hour(now()),minute(now()))
> [1] "2020122105"
Not only looks horrible, but also does not pad zeroes for days and hours as required. I can tweak the relevant ones further for zero-padding, but I was wondering if there is a more elegant way of reversing the typical string-to-datetime conversion.