我正在开发一个项目,它与 parking 有关,并且包含一个数据库。我有一个可变的时间戳,用于显示汽车进入 parking 场时的时间/日期,以及汽车在导出时的时间/日期。 我想得到小时数的差异(每个整小时后的分钟是一个新的小时等。4小时和2分钟与5小时相同),这样我就可以计算服务的价格(小时乘以每小时的价格)。
请帮助我,提前谢谢您
最佳答案
获取以毫秒为单位的差异并计算如下
long timeDiff = endTime.getTime() - startTime.getTime()
int hours = (int)Math.ceil(timeDiff/1000*60*60) //In here we are converting milli seconds difference to hours and then if it is not an exact number we are converting that to the next integer
关于java - Java 中两个 Timestamp 对象之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34980942/