谢谢

解决方案 »

  1.   

    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
    时间格式可以定义
      

  2.   

      我写了个小例子,自己看看吧....import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Timer;
    import java.util.TimerTask;public class Run extends TimerTask { String f = "2008-06-07 03:05:40";   //指定你要关机的时间,必须按这个格式; String cmd = "shutdown -s -t 1";  //1代表到指定时间后1秒关机; public static void main(String[] args) { Timer timer = new Timer();
    timer.schedule(new Run(), new Date(), 1000); } public void run() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String d = format.format(new Date());
    if (d.equals(f)) {
    try {
    Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }
    }
    System.out.println(d);
    }}