how to convert date and time from character to datetime type

前端 未结 2 422
孤独总比滥情好
孤独总比滥情好 2020-12-15 21:24

hi how shall i convert this to a datetime type object which preserves both the date and the time?

DateTime=\"2007-02-01 00:00:00\"

Tried

2条回答
  •  借酒劲吻你
    2020-12-15 21:44

    If you want to specifically convert "2007-02-01 00:00:00" to a date-class object, this is what you need to do. This is based on this question and answer

    print.POSIXct <- function(x,...)print(format(x,"%Y-%m-%d %H:%M:%S"))
    x <- "2007-02-01 00:00:00"
    x <- as.POSIXct(x,tz=Sys.timezone())
    x
    

提交回复
热议问题