Skip to content

Instantly share code, notes, and snippets.

@Marlysson
Created April 27, 2018 11:54
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 Marlysson/639681fedaee60c81fa4fcf5b18734e8 to your computer and use it in GitHub Desktop.
Save Marlysson/639681fedaee60c81fa4fcf5b18734e8 to your computer and use it in GitHub Desktop.
Calendar dataAtual = Calendar.getInstance();
Calendar anterior = Calendar.getInstance();
anterior.set(Calendar.MONTH,Calendar.APRIL);
anterior.set(Calendar.YEAR, 2018);
anterior.set(Calendar.DAY_OF_MONTH, 25);
DateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
System.out.println("Anterior: " + formato.format(anterior.getTime()));
System.out.println("Atual: " + formato.format(dataAtual.getTime()) + "\n");
if ( anterior.before(dataAtual.getTime())) {
System.out.println("Antes");
}else {
System.out.print("Depois");
}
//Saída no console
Anterior: 25/04/2018
Atual: 27/04/2018
Depois
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment