If you are willing to add dplyr
and lubridate
as dependencies you can generate the CSV with dates in ISO8601 (so you don't lose any information) like this:
#install.packages("tidyverse")
#install.packages("dplyr")
library(dplyr)
library(lubridate, warn.conflicts = FALSE)
dat <- data.frame(time=as.POSIXlt("2013-04-25 09:00 BST"), quantity=1) # example data
write.csv(mutate(dat, time=format(time, "%FT%H:%M:%S%z")), file="test.csv", row.names=FALSE)
That will generate a CSV file with the following content:
"time","quantity"
"2013-04-25T09:00:00+0200",1
As you can see the CSV contain the date in ISO8601 with the timezone information so no information is lost.
If you want to read back that CSV you can
df2 <- read.csv("test.csv") %>% mutate(time=ymd_hms(time))