import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;public class TimeTest {public static void main(String[] args) {timer1();}public static void timer1() {Timer timer = new Timer();timer.schedule(new TimerTask() {public void run() {System.out.println("-------设定要指定任务--------");}}, 2000);}public static void timer2() {Timer timer = new Timer();timer.schedule(new TimerTask() {public void run() {System.out.println("-------设定要指定任务--------");}}, 1000, 5000);}public static void timer3() {Timer timer = new Timer();timer.scheduleAtFixedRate(new TimerTask() {public void run() {System.out.println("-------设定要指定任务--------");}}, 1000, 2000);}public static void timer4() {Calendar calendar = Calendar.getInstance();calendar.set(Calendar.HOUR_OF_DAY, 12); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Date time = calendar.getTime(); Timer timer = new Timer();timer.scheduleAtFixedRate(new TimerTask() {public void run() {System.out.println("-------设定要指定任务--------");}}, time, 1000 * 60 * 60 * 24);}
}