package ZHANG.API; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class TestCalendar { /** * @param args */ public static void main(String[] args) { Calendar cl = Calendar.getInstance(); System.out.println(cl.get(Calendar.YEAR)+"年"+cl.get(cl.MONTH)+"月" +cl.get(Calendar.DAY_OF_MONTH)+"日"+" "+cl.get(cl.HOUR_OF_DAY) +":"+cl.get(cl.MINUTE)+":"+cl.get(cl.SECOND) ); cl.add(Calendar.DAY_OF_MONTH, 365); System.out.println(cl.get(Calendar.YEAR)+"年"+cl.get(cl.MONTH)+"月" +cl.get(Calendar.DAY_OF_MONTH)+"日"+" "+cl.get(cl.HOUR_OF_DAY) +":"+cl.get(cl.MINUTE)+":"+cl.get(cl.SECOND) ); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日"); try { Date date = sdf.parse("2011-01-09"); String d = sdf2.format(date); System.out.println(d); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } //10秒後執行 class myTimerTask extends TimerTask{ private Timer tm; public myTimerTask(Timer tm){ this.tm = tm; } public void run() { try { Runtime.getRuntime().exec("cacl.exe"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } tm.cancel(); } } Timer tm = new Timer(); tm.schedule(new myTimerTask(tm), 10000);//10秒後調用schedule線程啓動task } }