How to convert y%m%d%H format into “%Y%m%d %H:%M:%S” in time series data

后端 未结 2 1553
灰色年华
灰色年华 2021-01-29 15:13

How do I convert the y%m%d%H format into \"%Y%m%d %H:%M:%S\". My dates run from 1970 to 2010.

2条回答
  •  误落风尘
    2021-01-29 15:17

    Try this:

    R> Sys.Date()
    [1] "2012-07-23"
    R> format(Sys.Date())
    [1] "2012-07-23"
    R> format(Sys.Date(), "%Y-%m-%d %H:%M:%S")
    [1] "2012-07-23 00:00:00"
    R> 
    

    as you probably have a Date type which, by definition, has no hour/minute/second information--use POSIXct for that. See help(DateTimeClasses) the details, and a bazillion posts here and on the various mailing lists with working examples.

提交回复
热议问题