java 动态显示时间

阅读更多
import   java.util.Date;

public   class   Test   {

                /**
                  *   @param   args
                  *   @author   Goto
                  */
                public   static   void   main(String[]   args)   throws   Exception{
                                int   count   =   0;
                           
                                Date   date   =   new   Date(System.currentTimeMillis());
                                while   (count++   <   20)   {
                                                Thread.sleep(500);
                                                date.setTime(System.currentTimeMillis());
                                                System.out.println(date.toString());
                                }

                }
}






import   java.util.Timer;
import   java.util.TimerTask;
import   java.util.Date;

public   class   Test{
public   static   void   main(String[]   args){
Timer   t   =   new   Timer();
MyTimerTask   task   =   new   MyTimerTask();
t.schedule(task,1,1000);
}
}

class   MyTimerTask   extends   TimerTask{
public     void   run(){
Date   d   =   new   Date();
System.out.println(d.toString());
}
}

你可能感兴趣的:(Java,thread)