简体   繁体   English

如何四舍五入到最近的未来时间戳?

[英]How to round to the nearest future timestamp?

I am using the lubridate function round_date to round timestamps like below:我正在使用 lubridate function round_date 来圆形时间戳,如下所示:

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

This gives as "2015-11-26 23:50:00 +08"这给出了“2015-11-26 23:50:00 +08”

But I want to round it to future 5 mins not past.但我想将它舍入到未来 5 分钟而不是过去。 Like喜欢

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

should round all the timestamps from 2015-11-26 23:50:01 to 2015-11-26 23:54:59 to应该将所有时间戳从2015-11-26 23:50:012015-11-26 23:54:59

2015-11-26 23:55:00.

Any help is appreciated.任何帮助表示赞赏。

This should work.这应该有效。

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

rounds all all the timestamps from 2015-11-26 23:50:01 to 2015-11-26 23:54:59 to 2015-11-26 23:55:00 .2015-11-26 23:50:012015-11-26 23:54:592015-11-26 23:55:00的所有时间戳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM