Date d=new Date();//当天
Date date=new Date(d.getYear(),d.getMonth(),d.getDay()-3);//3天前
Date date=new Date(d.getYear()-1,d.getMonth(),d.getDay());//1年前
要作适当处理,比如d.getDay()-3<=0时,自己看着处理吧

解决方案 »

  1.   

    int syear  = getIntFromCombox(startYearCb);
    int smonth = getIntFromCombox(startMonthCb);
    int sdate  = getIntFromCombox(startDateCb);
    int shour  = getIntFromCombox(startHourCb);
    int eyear  = getIntFromCombox(endYearCb);
    int emonth = getIntFromCombox(endMonthCb);
    int edate  = getIntFromCombox(endDateCb);
    int ehour  = getIntFromCombox(endHourCb); ts_after3 = new Timestamp(syear-1900 + 3,1-1,1,0,0,0,0);
    ts_before3   = new Timestamp(eyear-1900 - 3,12-1,31,23,59,59,999999999);
      

  2.   

    楼上兄台:能不能解释一下Timestamp(syear-1900 + 3,1-1,1,0,0,0,0);
       Timestamp(eyear-1900 - 3,12-1,31,23,59,59,999999999);
    ?多谢了!还有:GregorianCalendar now=new GregorianCalendar();
    now.add(1,n);n是30的时候就不好使了??
      

  3.   

    用Calendar完全可以。
    看jdk的Calendar帮助!public abstract void add(int field,int amount)
    Date Arithmetic function. Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling: 
    add(Calendar.DATE, -5). 
    Parameters:
    field - the time field.
    amount - the amount of date or time to be added to the field.而且这里的add还有选择的方式,详细看看jdk吧,里边有答案。
      

  4.   

    还有roll(int field,int amount)方法。
    关键他的好处在于:add(int field,int amount)中的field参数,有不少常量,很方便,DAY_OF_YEAR,DAY_OF_MONTH,WEEK_OF_MONTH,WEEK_OF_YEAR

    总之,很多吧。
    我曾用jdk1。3写过一个类似window系统的日历组件就是用的Calendar,好使!
      

  5.   

    public abstract void add(int field,
                             int amount)
    Date Arithmetic function. Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling: 
    add(Calendar.DATE, -5).Parameters:
    field - the time field.
    amount - the amount of date or time to be added to the field.
      

  6.   

    Calendar好像有问题 7月只有30天?
      

  7.   

    多谢各位了!!!
    我用的是GregorianCalendar。
    再次感谢!!!
    我已经解决问题了。