Skip to content

Instantly share code, notes, and snippets.

@sandeepyohans
Created September 17, 2019 09:40
Show Gist options
  • Save sandeepyohans/45f555ad39deedbfd1f1291e20af7b5a to your computer and use it in GitHub Desktop.
Save sandeepyohans/45f555ad39deedbfd1f1291e20af7b5a to your computer and use it in GitHub Desktop.
Format Date and Increment it by 1 month
// Desired date pattern
String pattern = "MM-dd-yyyy";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String strDate;
// Current date
Date date = new Date();
// Current date in desired format
strDate = simpleDateFormat.format(date);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
// Increment date by 1 month
cal.add(Calendar.MONTH, 1);
date = cal.getTime();
strDate = simpleDateFormat.format(date);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment