Created
September 17, 2019 09:40
-
-
Save sandeepyohans/45f555ad39deedbfd1f1291e20af7b5a to your computer and use it in GitHub Desktop.
Format Date and Increment it by 1 month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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