内容简介:先生,您可以轻松使用java功能. long difference = date2.getTime() – date1.getTime();看看这翻译自:https://stackoverflow.com/questions/18908738/calculate-difference-between-two-times-android
我正在开发和 Android
应用程序,我需要计算两次之间的差异.我需要计算24小时的时差,以及两天的时间差(例如今天下午5点到明天上午9点).
我已经尝试了以下代码,计算仅适用于24小时的差异,
String dateStart = "08:00:00";
String dateStop = "13:00:00";
//HH converts hour in 24 hours format (0-23), day calculation
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
Date d1 = null;
Date d2 = null;
try
{
d1 = format.parse(dateStart);
d2 = format.parse(dateStop);
//in milliseconds
long diff = d2.getTime() - d1.getTime();
long diffHours = diff / (60 * 60 * 1000) % 24;
Log.e("test",diffHours + " hours, ");
}
catch (Exception e)
{
// TODO: handle exception
}
先生,您可以轻松使用 java 功能. long difference = date2.getTime() – date1.getTime();看看这 link 这将对你有所帮助.
翻译自:https://stackoverflow.com/questions/18908738/calculate-difference-between-two-times-android
以上所述就是小编给大家介绍的《java – 计算两次android之间的差异》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- c# – 程序集引用之间的差异
- c# – Unity 3D质量设置之间隐藏的差异?
- 【Redis】不同数据结构之间的差异及应用场景
- BEAM和JVM之间的一些基本特征/架构差异是什么?
- 编码人员,程序员,开发人员和软件工程师之间的差异
- c# – .NET中用户创建的结构和框架结构之间的差异
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Just My Type
Simon Garfield / Profile Books / 2010-10-21 / GBP 14.99
What's your type? Suddenly everyone's obsessed with fonts. Whether you're enraged by Ikea's Verdanagate, want to know what the Beach Boys have in common with easy Jet or why it's okay to like Comic Sa......一起来看看 《Just My Type》 这本书的介绍吧!