四舍五入到最近四分之一小时 [英] Rounding time to nearest quarter hour

查看:108
本文介绍了四舍五入到最近四分之一小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个POSIXct值的向量,我想把它们四舍五入到最近。我不在乎那一天。如何将值转换为小时和分钟?



例如,我想要的值



<$ p $



$ b

 20:45


解决方案

 格式(strptime 90%,%H:%M)+ round(as.numeric(your.time)/ 900)* 900,%H:%M 

将工作


I have a vector of POSIXct values and I would like to round them to the nearest quarter hour. I don't care about the day. How do I convert the values to hours and minutes?

For example, I would like the value

"2012-05-30 20:41:21 UTC"

to be

"20:45"

解决方案

something like

format(strptime("1970-01-01", "%Y-%m-%d", tz="UTC") + round(as.numeric(your.time)/900)*900,"%H:%M")

would work

这篇关于四舍五入到最近四分之一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆