How to increment time by 1 hour

后端 未结 3 1183
生来不讨喜
生来不讨喜 2020-12-20 15:18

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

相关标签:
3条回答
  • 2020-12-20 16:05
       Calendar calendar = Calendar.getInstance();
       calendar.setTime(previous_time);
       calendar.add(Calendar.HOUR, 1);
       previous_time = calendar.getTime();
       // do your comparison
    
    0 讨论(0)
  • 2020-12-20 16:06
    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

    0 讨论(0)
  • 2020-12-20 16:10

    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 current time string formate within add 1 hours

    0 讨论(0)
提交回复
热议问题