public static void main(String[] args) {
SimpleDateFormat simpleDateFormatH = new SimpleDateFormat("HH");
SimpleDateFormat simpleDateFormatM = new SimpleDateFormat("mm");
SimpleDateFormat simpleDateFormatS = new SimpleDateFormat("ss");
String hh = simpleDateFormatH.format(new Date());
String mm = simpleDateFormatM.format(new Date());
String ss = simpleDateFormatS.format(new Date());
int Sum = 0;
if(18>Integer.parseInt(hh)) {
int h1 = 16-Integer.parseInt(hh);
Sum = h1*60*60-Integer.parseInt(mm)*60-Integer.parseInt(ss);
}else if(18<Integer.parseInt(hh)) {
int h1 = Integer.parseInt(hh)-14;
Sum = h1*60*60-Integer.parseInt(mm)*60-Integer.parseInt(ss);
}else if(18==Integer.parseInt(hh)) {
if(Integer.parseInt(mm)==0&&Integer.parseInt(ss)==0) {//这个情况是刚好6点00.00启动的软件
Sum = 24*60*60;
}else {//情况为6点零几分
Sum = 24*60*60-Integer.parseInt(mm)*60-Integer.parseInt(ss);
}
}
System.out.println("liuchang ########### 系统时间:"+hh+"--"+mm+"--"+ss);
System.out.println("liuchang ############# Sum:"+Sum);
try {
Runtime.getRuntime().exec("shutdown -r -t "+Sum);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
重启电脑的命令使用的是cmd命令重启电脑
shutdown -s -t 60,s即shutdown的缩写,t即time的缩写,意思是60秒后关机。
shutdown -r -t 60,r即restart的缩写,意思是60秒后重启;
shutdown -l -t 60,l即logout的缩写,意思是60秒后注销;
shutdown -h -t 60,h即hibernate的缩写,意思是60秒后休眠;
shutdown -a,a即all的缩写,意思是取消所有的shutdown命令,但是不能取消上一步的命令;
当执行了重启命令后,在倒计时内使用cmd窗口 shutdown -a命令就可以取消重启。测试会用到的。