import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class TimeTask { /** * @param args * @throws ParseException */ public static void main(String[] args) throws ParseException { // TODO Auto-generated method stub Timer timer = new Timer(); TimerTask task = new SynchroTimerTask(timer); SimpleDateFormat sf2= new SimpleDateFormat("yyyy-MM-dd"); String year= sf2.format(new Date()); SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date firstTime = sf1.parse(year+" 09:52:00"); long period = 1000 * 600; System.out.println("白天----开始执行定时任务"); timer.scheduleAtFixedRate(task, firstTime, period); } }