Re: Timer Schedule TimerTask for same hour every day
- From: Tomer <tomerbd1@xxxxxxxxx>
- Date: Mon, 30 Jun 2008 02:08:39 -0700 (PDT)
On Jun 29, 7:08 pm, Arne Vajhøj <a...@xxxxxxxxxx> wrote:
Tomer wrote:
If the current time is 18:50 and ischeduleRepeating dailyTimerTask
to 18:52 then everything is file its being run at 18:52 daily however
if ischeduleit to 18:48 then its being run immediately (and i dont
want that) as i run the application :(
However i wanted it to be runeverydayat 18:48! how can i achieve
that?
Timertimer= newTimer();
Calendar date = Calendar.getInstance();
//Timerstarts yesterday (so that surely will run today when time
comes.
// date.setTimeInMillis(new Date().getTime() - 1000 * 60 * 60 * 24);
DateFormat sdf = new SimpleDateFormat("HH:mm");
Date dateToBackup = null;
try {
dateToBackup = sdf.parse("18:32");
} catch (ParseException e) {
e.printStackTrace();
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateToBackup);
date.set(Calendar.HOUR, calendar.get(Calendar.HOUR));
date.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE));
date.set(Calendar.SECOND, calendar.get(Calendar.SECOND));
date.set(Calendar.MILLISECOND, 0);
Why not just roll onedayforward ?
//Scheduleto runeveryday.
timer.schedule(
new TestTimerTask(),
date.getTime(),
1000 * 60 * 60 * 24
);
Thread.sleep(120000);
}
}
Arne
I didnt want to roll one day forward because i didnt want to have
special cases in my code like checking if the current time is later
than scheduled time and in that case roll one day forward, but now
that i see i have no choice, then i would need to check for that
special case and roll one day forward.
Thanks,
Tomer
.
- References:
- Timer Schedule TimerTask for same hour every day
- From: Tomer
- Re: Timer Schedule TimerTask for same hour every day
- From: Arne Vajhøj
- Timer Schedule TimerTask for same hour every day
- Prev by Date: Re: X.509 cert not exporting CA chain?
- Next by Date: Re: FTPClient and CopyStreamAdapter stop sometimes
- Previous by thread: Re: Timer Schedule TimerTask for same hour every day
- Next by thread: Re: Timer Schedule TimerTask for same hour every day
- Index(es):
Relevant Pages
|