import java.text.*;import java.util.*;
public class Time 
{public static void main(String[] args) 
  {   String s="2011年11月11日";
SimpleDateFormat form=new SimpleDateFormat("yyyy年MM月dd日");
       try{   Date date=null;
           date=form.parse(s);
           System.out.print(date);  
           
        date.setDate(date.getDate()+100);
        
       
       
       System.out.println("  "+form.format(date));
       
       
          }

  catch(ParseException e)
  { System.out.print(e); 
  
  }
 
}

 }这是程序输出的结果:
Fri Nov 11 00:00:00 CST 2011  2012年02月19日
 次行date.setDate(date.getDate()+100);setDate getDate都被划上"——"但任正确输出 eclipse提示的是:
the method getDate() from the type Date is deprecated
是不是这个方法现在不用,那有其他方法实现相同的功能吗?

解决方案 »

  1.   

     可以用的 ,不过不推荐使用  以后可能会弃用吧
    用Calendar
      

  2.   

    现在一般都是用calender类来做日期操作,date类能直接操作的很少,大部分都过时了
      

  3.   

    Calendar c = Calendar.getInstance();
    c.add(c.DATE, +1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    System.out.println(sdf.format(c.getTime()));
      

  4.   

    文档中已经说明了,用Calendar。"getDate()           已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.DAY_OF_MONTH) 取代。"package com.study.pratice03;import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;public class Time
    {
    public static void main(String[] args)
    {
    // TODO Auto-generated method stub
    String s = "2011年11月11日";
    SimpleDateFormat form = new SimpleDateFormat("yyyy年MM月dd日");
    try
    {
    Date date = null;
    date = form.parse(s);
    System.out.print(date); //date.setDate(date.getDate() + 100);
    Calendar cl=Calendar.getInstance();
    cl.setTime(date);
    cl.add(Calendar.DAY_OF_MONTH, 100);
    System.out.println(" " + form.format(cl.getTime())); } catch (ParseException e)
    {
    System.out.print(e); } }}
      

  5.   

    String s = "2011年11月11日";
    SimpleDateFormat form = new SimpleDateFormat("yyyy年MM月dd日");
    Calendar date = Calendar.getInstance();
    try {
    date.setTime(form.parse(s));
    } catch (ParseException e) {
    e.printStackTrace();
    }
    date.add(date.DATE, +100);
    System.out.println(form.format(date.getTime()));