vickzhu

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            151 隨筆 :: 0 文章 :: 34 評論 :: 0 Trackbacks
           

          import java.text.ParseException;

          import java.text.SimpleDateFormat;

          import java.util.Date;

          import java.util.Timer;

          import java.util.TimerTask;

          publicclass TestTimer {

             

              publicstaticvoid main(String[] args) throws ParseException {

                 TestTimer tt=new TestTimer();

                 tt.vick();

              }   

              publicvoid vick() throws ParseException{

                 Timer timer=new Timer();

                 Test timerTask=new Test();

                 SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                 Date d=df.parse("2008-08-21 09:00:00");   //在這里設置開始時間

                 long delay=d.getTime()-System.currentTimeMillis();   //延遲多少毫秒后開始調用

                 long cycle=24*60*60*1000;   //循環調用的時間間隔

                 timer.schedule(timerTask, delay, cycle);

              }

          }

          class Test extends TimerTask{

              privateinti=1;

              publicvoid run() {

                 System.out.println("這是第 "+i+" 次調用,時間為:"+new Date());

                 i++;

              }

          }

          posted on 2008-08-20 14:32 筱 筱 閱讀(525) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 泽库县| 花莲市| 泰顺县| 客服| 增城市| 肥西县| 江西省| 赣榆县| 丹阳市| 沙雅县| 田林县| 昌黎县| 南雄市| 华阴市| 稷山县| 青浦区| 株洲市| 闵行区| 米易县| 伊宁县| 奈曼旗| 梨树县| 舞钢市| 天等县| 绵阳市| 富蕴县| 嵊州市| 左云县| 镇坪县| 郯城县| 宝山区| 富蕴县| 桓台县| 娱乐| 海南省| 稷山县| 奉新县| 墨脱县| 永新县| 和平县| 砀山县|