-4

I need to know how to get the the time. I am trying to make it run something at the top of every hour( 1:00, 2:00, 3:00, etc.). If you could help me that would be great!

Brandon
  • 16,382
  • 12
  • 55
  • 88

2 Answers2

2

If you need to run something hourly use java.util.Timer:

 long hour = 1000L*3600L;
 Timer timer = new Timer();
 timer.schedule(new TimerTask() {
   public void run() {
      // Do this hourly
   }
 }, hour, hour); // first delay, period
Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
1

You should look at the Quartz library (a well known Java scheduler) with a cron expression like

0 0 * ? * *

( = When times matches 0 seconds, 0 minutes, any hour, every day);

Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148