Round a POSIX date (POSIXct) with base R functionality

前端 未结 3 794
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 04:25

I\'m currently playing around a lot with dates and times for a package I\'m building.

Stumbling across this post reminded me again that it\'s generally not a bad ide

3条回答
  •  青春惊慌失措
    2020-12-03 04:59

    base has round.POSIXt to do this. Not sure why it doesn't come up with methods.

    x <- as.POSIXct(Sys.time())
    x
    [1] "2012-07-04 10:01:08 BST"
    round(x,"mins")
    [1] "2012-07-04 10:01:00 BST"
    round(x,"hours")
    [1] "2012-07-04 10:00:00 BST"
    round(x,"days")
    [1] "2012-07-04"
    

提交回复
热议问题