Java : how to add 10 mins in my Time

前端 未结 8 1863
闹比i
闹比i 2020-11-27 21:00

I am getting this time

String myTime = \"14:10\";

Now I want to add like 10 mins to this time, so that it would be 14:20

8条回答
  •  难免孤独
    2020-11-27 21:26

    Something like this

     String myTime = "14:10";
     SimpleDateFormat df = new SimpleDateFormat("HH:mm");
     Date d = df.parse(myTime); 
     Calendar cal = Calendar.getInstance();
     cal.setTime(d);
     cal.add(Calendar.MINUTE, 10);
     String newTime = df.format(cal.getTime());
    

    As a fair warning there might be some problems if daylight savings time is involved in this 10 minute period.

提交回复
热议问题