日期:2014-05-20 浏览次数:20765 次
public class TimerDemo { /** * 得到下一个整点时间 * @return */ public static Date getNextFullTime(){ Calendar calendar = Calendar.getInstance(); Date date = null; if(calendar.get(Calendar.MINUTE) == 0 ){ date = calendar.getTime(); }else{ date = new Date(calendar.get(Calendar.YEAR) - 1900, calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY) + 1, 0 , 0); } return date; } public static void main(String[] args) { Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { JOptionPane.showMessageDialog(null, "时间到 " + new Date().toLocaleString()); } }, TimerDemo.getNextFullTime() , 3600000); } }
------解决方案--------------------
Timer和TimerTask可以实现