Why is the month changed to 50 after I added 10 minutes?

The issue for you is that you are using mm. You should use MM. MM is for month and mm is for minutes. Try with yyyy-MM-dd HH:mm Other approach: It can be as simple as this (other option is to use joda-time) static final long ONE_MINUTE_IN_MILLIS=60000;//millisecs Calendar date = Calendar.getInstance(); long t= date.getTimeInMillis(); Date afterAddingTenMins=new … Read more

How to subtract X day from a Date object in Java?

Java 8 and later With Java 8’s date time API change, Use LocalDate LocalDate date = LocalDate.now().minusDays(300); Similarly you can have LocalDate date = someLocalDateInstance.minusDays(300); Refer to https://stackoverflow.com/a/23885950/260990 for translation between java.util.Date <–> java.time.LocalDateTime Date in = new Date(); LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault()); Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); Java 7 and earlier Use Calendar‘s add() … Read more

Convert java.util.Date to String

Convert a Date to a String using DateFormat#format method: String pattern = “MM/dd/yyyy HH:mm:ss”; // Create an instance of SimpleDateFormat used for formatting // the string representation of date according to the chosen pattern DateFormat df = new SimpleDateFormat(pattern); // Get the today date using Calendar object. Date today = Calendar.getInstance().getTime(); // Using DateFormat format … Read more