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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 清流县| 桐庐县| 大方县| 英山县| 那坡县| 泸州市| 竹溪县| 大港区| 南乐县| 漠河县| 建宁县| 乐至县| 富宁县| 斗六市| 南漳县| 大兴区| 余姚市| 苏尼特左旗| 来凤县| 正阳县| 信阳市| 固镇县| 新河县| 灵川县| 武宁县| 丽水市| 庆城县| 淮阳县| 星座| 高州市| 内丘县| 璧山县| 汽车| 阳信县| 八宿县| 中阳县| 盐城市| 靖安县| 西华县| 汝城县| 鲁山县|