public class CleanUp extends TimerTask { // expressed in milliseconds private final static long ONCE_PER_MONTH = 1000 * 60 * 60 * 24 * 30; // Pre-define 1 mth = 30 days
public void run() { System.out.println("Cleaning Roger cubical ...in progress..."); }
private static Date getTomorrowMorning8am() { Calendar tomorrow = new GregorianCalendar(); tomorrow.add(Calendar.DATE, 1); Calendar result = new GregorianCalendar(tomorrow.get(Calendar.YEAR), tomorrow.get(Calendar.MONTH), tomorrow.get(Calendar.DATE), 8, 0); return result.getTime(); }
public static void main(String[] args) { TimerTask cleanup = new CleanUp(); // perform the task once a month at 8am, starting tomorrow morning // (other style are possible as well) Timer timer = new Timer(); timer.scheduleAtFixedRate(cleanup, getTomorrowMorning8am(),ONCE_PER_MONTH); } }
3 Comments:
Ken Leeeeeeeee..... you look so cheeky in this picture! Roger also shy shy dy.... :P
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;
public class CleanUp extends TimerTask {
// expressed in milliseconds
private final static long ONCE_PER_MONTH = 1000 * 60 * 60 * 24 * 30; // Pre-define 1 mth = 30 days
public void run() {
System.out.println("Cleaning Roger cubical ...in progress...");
}
private static Date getTomorrowMorning8am() {
Calendar tomorrow = new GregorianCalendar();
tomorrow.add(Calendar.DATE, 1);
Calendar result = new GregorianCalendar(tomorrow.get(Calendar.YEAR), tomorrow.get(Calendar.MONTH), tomorrow.get(Calendar.DATE), 8, 0);
return result.getTime();
}
public static void main(String[] args) {
TimerTask cleanup = new CleanUp();
// perform the task once a month at 8am, starting tomorrow morning
// (other style are possible as well)
Timer timer = new Timer();
timer.scheduleAtFixedRate(cleanup, getTomorrowMorning8am(),ONCE_PER_MONTH);
}
}
*Just like chipsmore, kejap ada kejap takde*
Did anyone notice ... the tan-skinned chap? Who is he? Scary liao! Like the prank shadow. Super Kitty must prevail!!! Go Kitty, GO!!! MEOW...
Post a Comment
Subscribe to Post Comments [Atom]
<< Home