My question comes from this question. The question had the following character string.
x <- \"2007-02-01 00:00:00\"
y <- \"02/01/2007 00:06:10\"
It is just the print
that remove the precision if the time part of a date is a midnight. This is literlay explained in ??strftime
help, specially the format parameter:
A character string. The default is "%Y-%m-%d %H:%M:%S" if any component has a time component which is not midnight, and "%Y-%m-%d" otherwise
One idea is to redefine the S3 method print
for POSIXct object:
print.POSIXct <- function(x,...)print(format(x,"%Y-%m-%d %H:%M:%S"))
Now for your example if your print your x date(with midnight part) you get:
x <- "2007-02-01 00:00:00"
x <- as.POSIXct(x,tz=Sys.timezone())
x
[1] "2007-02-01 00:00:00"