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

calendar dates

 
lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
lusha
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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));
System.out.println(ts);
try for month (need to take care of varing no of days of month)
-arun
[ February 19, 2002: Message edited by: Arun Boraiah ]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this from Servlets -> Java In General (Beginners)
 
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());
}


here replace -1 with -7 to get prev weeks calendar dates...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic