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!
Asked
Active
Viewed 268 times
-4
-
1Google `java get time` – Sotirios Delimanolis May 22 '13 at 18:19
-
1Have you done *any* research before asking this question? – Marc Claesen May 22 '13 at 18:37
2 Answers
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