Skip to content

Instantly share code, notes, and snippets.

@dedunumax
Last active January 4, 2016 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedunumax/8630142 to your computer and use it in GitHub Desktop.
Save dedunumax/8630142 to your computer and use it in GitHub Desktop.
How to get the day prior to a particular date.
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* Date -1
* Get the date prior to a specific date.
*/
public class DateMinusOne {
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = null;
try {
date = format.parse("20131201080301");
} catch (Exception e) {
e.printStackTrace();
return;
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, -1);
date = cal.getTime();
System.out.println(date.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment