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);
An easy way is to use apache DateUtils.
DateUtils
import org.apache.commons.lang.time.DateUtils; DateUtils.addSeconds(now, 5); // Add 5 seconds. DateUtils.addSeconds(now, -5); // Subtracting 5 seconds
You can also add/subtract minutes, hours, and so on...