时差(小时) [英] Time difference in hours

查看:37
本文介绍了时差(小时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算两个不同 Time 实例的小时数差异.我从数据库中获取这些值作为 :datetime 列

I am trying to get the difference in hours for two different Time instances. I get these values from the DB as a :datetime column

我怎样才能做到这一点,以便在忽略或四舍五入分钟的同时在计算中包括月份和年份?这只能手动完成还是有功能可以做到这一点?

How can I do this so that it includes the months and years as well in the calculation while ignoring or rounding the minutes? Can this only be done manually or is there a function to do this?

推荐答案

((date_2 - date_1) / 3600).round

((date_2 - date_1) / 1.hour).round

这篇关于时差(小时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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