File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes calendar dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calendar dates" Watch "calendar dates" New topic

calendar dates

lusha tak
Ranch Hand

Joined: Dec 30, 2000
Posts: 185
Hello all!!
how is everybody doing??
hey, i have a query regarding calendar dates.
is there any way to gat caendar dates for the previous week/previous month using java.util package(i.e. if today it is 19/02/2002,how do we get exactly a week's prior date 12/02/2002 )?
thanks in advance
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
import java.sql.Timestamp class
below line of code will take current time in millisecond and sub one week time in millisecond. this will give a time sttamp object which now will be one week old date. Which you can use
Timestamp ts=new Timestamp( System.currentTimeMillis() - (24*60*60*7*1000));
try for month (need to take care of varing no of days of month)
[ February 19, 2002: Message edited by: Arun Boraiah ]

Sharing is learning
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Moving this from Servlets -> Java In General (Beginners)
Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 160
import java.util.Date;
import java.util.Calendar;
public class Prev
public static void main(String args[])
Calendar xx = Calendar.getInstance();
Date dt = null;
dt = xx.getTime();
System.out.println("Yesterday Is : " + dt.getDate());

here replace -1 with -7 to get prev weeks calendar dates...

Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
I agree. Here's the link:
subject: calendar dates
It's not a secret anymore!