如何通过增加1小时递增时间小时、时间

2023-09-05 02:27:05 作者:独久厌闹

我有两个时间值。一个用于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();
   //做你的比较
 

移动互联网日使用时长增加1小时以上,小镇青年2.5亿

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