search

Home  >  Q&A  >  body text

java.util.Timer.schedule如何避免启动时指定时间过了就立刻执行一次?

schedule的开始时间设置的是一个固定时间,比如中午12点,如果过了12点启动,那么会立刻执行一次,有没有办法能过了任务的指定开始时间就不执行了等下一次?

ringa_leeringa_lee2802 days ago832

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 10:00:53

    public void schedule(TimerTask task, long delay, long period)

    Isn’t it possible to use this interface? Calculate the number of milliseconds from the current time to 12 noon delayperiod是今天中午12点至明天中午12点就是24小时的毫秒数。这样如果当前时间超过12点了。那delay and it will be the next 12 o'clock.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:00:53

    Can you add a method to judge whether the current time is not equal to the scheduled time and not start it? I have never done this...

    reply
    0
  • Cancelreply