My question comes from this question . The question had the following line of characters.
x <- "2007-02-01 00:00:00" y <- "02/01/2007 00:06:10"
If you try to convert this string to a date class object, something funny will happen.
This is a sample from @nrusell's answer.
as.POSIXct(x,tz=Sys.timezone()) [1] "2007-02-01 EST" as.POSIXct(y,format="%m/%d/%Y %H:%M:%S",tz=Sys.timezone()) [1] "2007-02-01 00:06:10 EST"
As you can see, 00:00:00 disappears from the first example. @Richard Scriven posted the following example in our discussion using lubridate .
dt <- as.POSIXct("2007-02-01 00:00:00") hour(dt) <- hour(dt)+1 dt [1] "2007-02-01 01:00:00 EST" hour(dt) <- hour(dt)-1 dt [1] "2007-02-01 EST"
Again 00:00:00 disappears. Why does not R save 00:00:00 in a date class object after conversion? How can we save 00:00:00 ?
source share