这是我自己参考资料写了一个java定时器
源代码在线查看: quarteralarm.java
package dark.timer.example;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.tiling.scheduling.Scheduler;
import org.tiling.scheduling.SchedulerTask;
import dark.timer.QuarterIterator;
public class QuarterAlarm
{
private final Scheduler scheduler = new Scheduler();
private final SimpleDateFormat dateFormat =
new SimpleDateFormat("dd MMM yyyy HH:mm:ss.SSS");
private final int dayOfMoth, hourOfDay, minute, second;
public QuarterAlarm(int dayOfMoth, int hourOfDay, int minute, int second)
{
this.dayOfMoth = dayOfMoth;
this.hourOfDay = hourOfDay;
this.minute = minute;
this.second = second;
}
public void start()
{
scheduler.schedule(new SchedulerTask()
{
public void run()
{
soundAlarm();
}
private void soundAlarm()
{
System.out.println(
"Wake up! " + "It's " + dateFormat.format(new Date()));
// Start a new thread to sound an alarm...
}
}, new QuarterIterator(dayOfMoth, hourOfDay, minute, second));
}
public static void main(String[] args)
{
QuarterAlarm alarmClock = new QuarterAlarm(17, 13, 18, 0);
alarmClock.start();
}
}