As @Richard Scriven pointed out, you should not use as.Date , because it is not a datetime class. Here are some ways:
DateTime <- "2007-02-01 00:00:00" DateTime2 <- "02/01/2007 00:06:10" ## default format Ymd H:M:S > as.POSIXct(DateTime,tz=Sys.timezone()) [1] "2007-02-01 EST" > as.POSIXlt(DateTime,tz=Sys.timezone()) [1] "2007-02-01 EST" ## ## specify format m/d/YH:M:S > as.POSIXct(DateTime2,format="%m/%d/%Y %H:%M:%S",tz=Sys.timezone()) [1] "2007-02-01 00:06:10 EST" > as.POSIXlt(DateTime2,format="%m/%d/%Y %H:%M:%S",tz=Sys.timezone()) [1] "2007-02-01 00:06:10 EST" ## ## using lubridate library(lubridate) > ymd_hms(DateTime,tz=Sys.timezone()) [1] "2007-02-01 EST" > mdy_hms(DateTime2,tz=Sys.timezone()) [1] "2007-02-01 00:06:10 EST"
You do not need to specify format= for as.POSIXct and as.POSIXlt if you have the format %Y-%m-%d %H:%M:%S In other cases, such as %m/%d/%Y %H:%M:%S , you should usually specify the format explicitly.
source share