用Calendar类来获得,方法较多,请查一下它的api文档。

解决方案 »

  1.   

    先用SimpleDateFormat将string转换成date,
    然后用Calendar的setTime和add方法就算你想要的日期
      

  2.   

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date d1, d2;
        d1 = df.parse(cur_date);    Calendar c=Calendar.setTime(d1)......;???没有这个方法阿
      //请高手帮补上我真得好急
      

  3.   

    去查一下api文档,有了这个过程,你以后用的就更熟了
      

  4.   

    Method Summary 
    abstract  void add(int field, int amount) 
              Date Arithmetic function. 
     boolean after(Object when) 
              Compares the time field records. 
     boolean before(Object when) 
              Compares the time field records. 
     void clear() 
              Clears the values of all the time fields. 
     void clear(int field) 
              Clears the value in the given time field. 
     Object clone() 
              Overrides Cloneable 
    protected  void complete() 
              Fills in any unset fields in the time field list. 
    protected abstract  void computeFields() 
              Converts the current millisecond time value time to field values in fields[]. 
    protected abstract  void computeTime() 
              Converts the current field values in fields[] to the millisecond time value time. 
     boolean equals(Object obj) 
              Compares this calendar to the specified object. 
     int get(int field) 
              Gets the value for a given time field. 
     int getActualMaximum(int field) 
              Return the maximum value that this field could have, given the current date. 
     int getActualMinimum(int field) 
              Return the minimum value that this field could have, given the current date. 
    static Locale[] getAvailableLocales() 
              Gets the list of locales for which Calendars are installed. 
     int getFirstDayOfWeek() 
              Gets what the first day of the week is; e.g., Sunday in US, Monday in France. 
    abstract  int getGreatestMinimum(int field) 
              Gets the highest minimum value for the given field if varies. 
    static Calendar getInstance() 
              Gets a calendar using the default time zone and locale. 
    static Calendar getInstance(Locale aLocale) 
              Gets a calendar using the default time zone and specified locale. 
    static Calendar getInstance(TimeZone zone) 
              Gets a calendar using the specified time zone and default locale. 
    static Calendar getInstance(TimeZone zone, Locale aLocale) 
              Gets a calendar with the specified time zone and locale. 
    abstract  int getLeastMaximum(int field) 
              Gets the lowest maximum value for the given field if varies. 
    abstract  int getMaximum(int field) 
              Gets the maximum value for the given time field. 
     int getMinimalDaysInFirstWeek() 
              Gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, getMinimalDaysInFirstWeek returns 1. 
    abstract  int getMinimum(int field) 
              Gets the minimum value for the given time field. 
     Date getTime() 
              Gets this Calendar's current time. 
     long getTimeInMillis() 
              Gets this Calendar's current time as a long. 
     TimeZone getTimeZone() 
              Gets the time zone. 
     int hashCode() 
              Returns a hash code for this calendar. 
    protected  int internalGet(int field) 
              Gets the value for a given time field. 
     boolean isLenient() 
              Tell whether date/time interpretation is to be lenient. 
     boolean isSet(int field) 
              Determines if the given time field has a value set. 
    abstract  void roll(int field, boolean up) 
              Time Field Rolling function. 
     void roll(int field, int amount) 
              Time Field Rolling function. 
     void set(int field, int value) 
              Sets the time field with the given value. 
     void set(int year, int month, int date) 
              Sets the values for the fields year, month, and date. 
     void set(int year, int month, int date, int hour, int minute) 
              Sets the values for the fields year, month, date, hour, and minute. 
     void set(int year, int month, int date, int hour, int minute, int second) 
              Sets the values for the fields year, month, date, hour, minute, and second. 
     void setFirstDayOfWeek(int value) 
              Sets what the first day of the week is; e.g., Sunday in US, Monday in France. 
     void setLenient(boolean lenient) 
              Specify whether or not date/time interpretation is to be lenient. 
     void setMinimalDaysInFirstWeek(int value) 
              Sets what the minimal days required in the first week of the year are; For example, if the first week is defined as one that contains the first day of the first month of a year, call the method with value 1. 
     void setTime(Date date) 
              Sets this Calendar's current time with the given Date. 
     void setTimeInMillis(long millis) 
              Sets this Calendar's current time from the given long value. 
     void setTimeZone(TimeZone value) 
              Sets the time zone with the given time zone value. 
     String toString() 
              Return a string representation of this calendar. 
      

  5.   

    GregorianCalendar calendar = new GregorianCalendar();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date d1, d2;
        d1 = df.parse(cur_date);
             
    calendar.setGregorianChange(d1);
     calendar.set(calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH)-days);
    d2=calendar.getTime();
      

  6.   

    <%@ page import="java.util.*" %>
    <%@ page import="java.text.SimpleDateFormat" %>
    <%java.util.Calendar c=java.util.Calendar.getInstance();
    SimpleDateFormat   sDateFormat=new SimpleDateFormat("yyyy-MM-dd");
    c.add(java.util.Calendar.DAY_OF_MONTH,b);%>
    b为间隔的天数!
      

  7.   

    需要那么复杂吗?
    一种方法import java.util.*;
    import java.text.*;
    public Date getCertainTime(Stiring certainTime)
        Date returnValue = new Date();
        ParsePosition pp = new ParsePosition(0);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        returnValue = dateFormat.parse(certainTime,pp);
    }
    这么调用
    Date date = getCertainTime("2000-01-01 01:01:01");
      

  8.   

    还有其他方法,详细到www.javaspace.net上自己找
      

  9.   

    GregorianCalendar  grc=new  GregorianCalendar();  
    grc.setTime(new Date(date));  
    grc.add(GregorianCalendar.DATE,3);
      

  10.   

    呵呵,综合一下!  public String getDate(String cur_date,int days)
      {
        String str;
       //得到cur_date 第days天后的新日期
       //String result=getDate("2004-01-01",3);  //2004-01-04
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date d1=null,d2;
        try {
          d1 = df.parse(cur_date);
        }
        catch (Exception ex) {
        }    GregorianCalendar  grc=new  GregorianCalendar();  
        grc.setTime(d1);
        grc.add(Calendar.DAY_OF_MONTH,days);
        
        str = Integer.toString(grc.getTime().getDate());
        return str;
      }
      

  11.   

    java.util.Date+SimpleDataFromat+java.text
      

  12.   

    都不正确阿,大家有没有编译运行通过啊?
    主要是
    GregorianCalendar calendar = new GregorianCalendar();
             calendar.setGregorianChange(d1);
    这个地方有问题阿
    大家在帮帮忙
      

  13.   

    使用实例
    try {
                System.out.println(getDate("2004-08-14 2:50", 30));
            }
            catch (Exception e) {
                e.printStackTrace();
            }
    //String cur_date必须是yyyy-MM-dd HH:mm格式,不然会抛出异常,你也可以改成其它格式比如yyyy/MM/dd等
    public String getDate(String cur_date,int days) throws Exception {
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date date = sdf.parse(cur_date);
            java.util.Calendar cal = java.util.Calendar.getInstance();
            cal.setTime(date);
            cal.add(java.util.Calendar.DATE, days);
            date = cal.getTime();
            return sdf.format(date);
        }
      

  14.   

    public class NameApplication
    {
      public String getDate(String cur_date,int days)
      {
        String str;
       //得到cur_date 第days天后的新日期
       //String result=getDate("2004-01-01",3);  //2004-01-04
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date d1=null,d2;
        try {
          d1 = df.parse(cur_date);
        }
        catch (Exception ex) {
        }    GregorianCalendar  grc=new  GregorianCalendar();  
        grc.setTime(d1);
        grc.add(Calendar.DAY_OF_MONTH,days);
        
        str = Integer.toString(grc.getTime().getDate());
        return str;
      }  public static void main(String args[])
      {
        NameApplication t = new NameApplication();
        System.out.println(t.getDate("2004-01-02",4));
     }
    }
      

  15.   

    Calendar 自己看api,虽然费时间但对你好处多多啊