This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
all in a days work
Posted by Jody Brown on December 03, 2001 at 2:36 PM
Try this... import java.text.*; import java.util.*; class Dates { public static void main(String args[]) { SimpleDateFormat format = new SimpleDateFormat("MM, dd, yyyy"); Date myDate = new Date(); System.out.println("Date currently is " + format.format(myDate)); long dateMillis = myDate.getTime(); // subtract a day long dayInMillis = 1000 * 60 * 60 *24; dateMillis = dateMillis - dayInMillis; // set myDate to new time myDate.setTime(dateMillis); System.out.println("Date yesterday was " + format.format(myDate)); } }
Replies:
|