//date类的使用
import java.util.*;
import java.text.SimpleDateFormat;
 public class TestCalendar
{
  public static void main(String []args)
   {
    Calendar c1=Calendar.getInstance();
    System.out.println(c1.get(Calendar.YEAR)+" year "+c1.get(c1.MONTH)+" month " +c1.get(c1.DAY_OF_MONTH)+" day "+c1.get(c1.HOUR)+":"+c1.get(c1.MINUTE)+":"+c1.get(c1.SECOND));
    c1.add(c1.DAY_OF_YEAR,315);
     System.out.println(c1.get(Calendar.YEAR)+" year "+c1.get(c1.MONTH)+" month " +c1.get(c1.DAY_OF_MONTH)+" day "+c1.get(c1.HOUR)+":"+c1.get(c1.MINUTE)+":"+c1.get(c1.SECOND));
     
     SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd");
     SimpleDateFormat sdf2=new SimpleDateFormat("yyyy年MM月dd日");
                           
     try
        {
           Date d=sdf1.parse("2003-03-15");
           System.out.println(sdf2.format(d));
        }
     catch(Exception e)
         {  
          e.printStackTrace();     
         }
         
class MyTimerTask extends TimerTask
   {    
     private Timer tm=null;
     public MyTimerTask(Timer tm)
          {
             this.tm=tm;
          }
     public void run()
          {
            try{Runtime.getRuntime().exec("calc.exe");}
              catch(Exception e){e.printStackTrace();}
                      tm.cancel();
           }
      Timer tm=new Timer();
          tm.schedule(new MyTimerTask(tm),10000);                     
   }
 }
}

解决方案 »

  1.   

    package my.java.simple.demo;import java.util.Timer;
    import java.util.TimerTask;public class MyTimerTask extends TimerTask {
        
          private Timer tm=null;
          public MyTimerTask(Timer tm)
          {
              this.tm=tm;
          }
          public void run()
          {
              try{Runtime.getRuntime().exec("calc.exe");}
              catch(Exception e){e.printStackTrace();}
              tm.cancel();
          }
         
          
    }package my.java.simple.demo;import java.util.Timer;public class TestMyTimerTask {    /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Timer tm=new Timer();
            tm.schedule(new MyTimerTask(tm),1000);
        }}
     要好好理解什么是JAVA,这个是最基本的。
      

  2.   

    “Timer tm=new Timer();
      tm.schedule(new MyTimerTask(tm),10000);  ”这一段应该写在内部类的外面 or 内部类中的某一方法中