我有两个时间值。一个用于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