Last active
January 4, 2016 13:49
-
-
Save dedunumax/8630142 to your computer and use it in GitHub Desktop.
How to get the day prior to a particular date.
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
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