As described here and in other questions, it's fairly straight-forward to convert a Date object to POSIXct -- with the gotcha from ?as.POSIXct
that dates without times are treated as being midnight UTC. For example:
> Sys.timezone()
[1] "Europe/London"
> d <- as.Date("2016-06-01")
> as.POSIXct(d)
[1] "2016-06-01 01:00:00 BST"
I have two questions:
1) Why UTC? Wouldn't midnight in your current timezone make more sense, i.e. 2016-06-01 00:00:00 BST
?
2) Is there a more elegant way to get the actual midnight for a date than the following:
as.POSIXct(as.character(d))
By way of explanation, I have a function that takes a Date as an argument and then finds all the log events that happened on or after that date. With the standard behaviour outlined above, I'm missing all of the events between midnight and 1 am, and so I'm having to add the as.character
cast.