Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dates in java

 
Dinesh Bhogle
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get previous days date in java. i.e. current date-1
 
John Bateman
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I use the Calendar class as all familiar Date Constructor/methods are deprecated.

This backs up the calendar one day.
The Java 2 API docs are pretty good in showing how to use this class.
Hope this helped.
 
Senthil B Kumar
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.Date;
import java.util.Calendar;
public class Prev
{
public static void main(String args[])
{
Calendar xx = Calendar.getInstance();
Date dt = null;
xx.add(Calendar.DATE,-1);
dt = xx.getTime();
System.out.println("Yesterday Is : " + dt.getDate());
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic