I want to add 5 seconds to current time
Date date = new Date();
date.setSeconds(date.getSeconds()+ 5);
System.out.println(\"old Value is: \"+date);
You can try this. Calendar is the best solution you are looking at.
Date date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.parse("2014-04-17 14:53:25");
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.SECOND,(calendar.get(Calendar.SECOND)-5));
System.out.println(calendar.getTime());
Out put:
Thu Apr 17 14:53:20 IST 2014