谢谢
解决方案 »
- 关于java applet调用
- 数组问题
- 请问如何进行Java2D深入研究
- 英语不是很好 想在想学JAVA
- JSplitPane但分割条按钮问题
- 为什么java.lang.Math.sqrt(2)=1.4142135623730951
- 谁能说说 Collection的具体用法、作用?
- 怎么样才能更新一行数据而不是一列数据?
- 高分索取upload和download的源代码
- 谁能帮我详细解释:SwingUtilities.invokeLater()与SwingUtilities.invokeAndWait()
- Java中用什么方法循环播放音频?我能播放了,但不能循环
- 构造器中为什么super()调用必须在第一个语句??
时间格式可以定义
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);
}}