Java如何计算时差 [英] Java how to calculate time differences

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

问题描述

如果用户输入是 2255 和 2305,我如何计算 24 小时内的时差,输出应该是 10 分钟.我有一个想法是将输入分成 2 部分,2 位数字和 2 位数字.前 2 位数字是小时,乘以 60 使其为分钟.然后将其与第二个 2 位数相加,然后计算差异.我不想使用任何日期日历数据类型或 API 来解决它.谢谢

How can I calculate the time differences in 24 hour if the user input is 2255 and 2305 the output should be 10 minutes. I got an idea is to separate the input to 2 parts, 2 digits and 2 digits. the first 2 digits is the hour, times it to 60 to make it to minutes. Then plus it with the second 2 digits and then calculate the differences. I dont want use any Date Calendar data type or API to solve it. Thanks

推荐答案

如何在不使用 String chartAt 的情况下获取前 2 位数字.

How to get first 2 digit without using String chartAt.

最高两位数:数字/100最低两位数:数字 % 100

Highest two digits: number / 100 Lowest two digist: number % 100

但是如果用户输入 3:05 或 3-05,你会怎么做?我认为这是可用性问题.最好的解决方案是让用户界面完全可以理解.例如,您可以为小时和分钟使用单独的字段.

But what would you do if user enter 3:05 or 3-05? I think it's problem of usability. Best solution is making UI definitely understandable for user. For example you can use separate fields for hours and minutes.

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

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