如何取整到最近的未来时间戳?

问题描述 投票:0回答:1

我使用 lubridate 函数 round_date 来取整时间戳,如下所示。

round_date(as.POSIXct("2015-11-26 23:51:15"),"5 mins")

结果是 "2015-11-26 23: 50: 00 +08"

但我想把它舍弃到未来的5分钟,而不是过去。譬如

round_date(as.POSIXct("2015-11-26 23:51:15"),"5 mins")

应将所有时间戳从 2015-11-26 23:50:012015-11-26 23:54:59

2015-11-26 23:55:00.

任何帮助是感激的。

r datatable lubridate
1个回答
2
投票

这个应该可以。

lubridate::ceiling_date(as.POSIXct("2015-11-26 23:54:49"),"5 mins")

四舍五入所有的时间戳,从 2015-11-26 23:50:012015-11-26 23:54:592015-11-26 23:55:00.

© www.soinside.com 2019 - 2024. All rights reserved.