How to increase time by 1 hour

I have two times. one for the previous login time and one for the current login time. I have to increase the login time by one hour. I used the date format hh: mm: ss. This is my piece of code.

Date previous_time, current_time; if(previous_time.before(current_time)){ Log.i("Time Comparision"," true"); } 

therefore, instead of the above if condition, I have to add one hour to the previous_time and fulfill the if condition. How to achieve this?

+7
source share
3 answers
  Calendar calendar = Calendar.getInstance(); calendar.setTime(previous_time); calendar.add(Calendar.HOUR, 1); previous_time = calendar.getTime(); // do your comparison 
+24
source
 previous_time.setTime(previous_time.getTime() + 60 * 60 * 1000); 

or

 Date session_expiry = new Date(previous_time.getTime() + 60 * 60 * 1000); 

http://download.oracle.com/javase/6/docs/api/java/util/Date.html#getTime%28%29

+3
source

Please try this code.

  SimpleDateFormat sdf = new SimpleDateFormat("h:mm a"); Date date = Utils.getBookingDate(mBooking.ToTime); Calendar calendarAdd = Calendar.getInstance(); calendarAdd.setTime(date); calendarAdd.add(Calendar.HOUR, 1); toTime = sdf.format(calendarAdd.getTime()); tv_Totime.setText(toTime); 

when the current time formation is formed within 1 hour

+1
source

All Articles