如何通过增加1小时递增时间 [英] How to increment time by 1 hour
本文介绍了如何通过增加1小时递增时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个时间值。一个用于previous登录时间和一个用于当前登录时间。 我有一个小时,以增加previous时间登录。我已经使用的日期格式为hh:mm:ss的。 这是我的code段。
日期previous_time,CURRENT_TIME;
如果(previous_time.before(CURRENT_TIME)){
Log.i(时间比较,真);
}
所以,而不是上面提到的条件的话,我一小时增加至previous_time并执行,如果条件。如何实现这一目标?
解决方案
台历挂历= Calendar.getInstance();
calendar.setTime(previous_time);
calendar.add(Calendar.HOUR,1);
previous_time = calendar.getTime();
//做你的比较
I have two time values. one for the previous login time and one for the current login time. I have to increase previous time login by one hour. I have used the date format hh:mm:ss. This is my code snippet.
Date previous_time, current_time;
if(previous_time.before(current_time)){
Log.i("Time Comparision"," true");
}
so instead of the above mentioned if condition, I have to add one hour to the previous_time and do the if condition. How to achieve this?
解决方案
Calendar calendar = Calendar.getInstance();
calendar.setTime(previous_time);
calendar.add(Calendar.HOUR, 1);
previous_time = calendar.getTime();
// do your comparison
这篇关于如何通过增加1小时递增时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文