package demo01; import java.io.IOException; import java.util.Date; /** * 倒计时关机 */ public class Demo02 { public static void main(String[] args) throws IOException,InterruptedException { //倒计时多少秒后关机 int s =60; //60秒后的时间 Date mb =new Date(); mb.setMinutes(mb.getMinutes()+1);//原有分钟+1 long a = mb.getTime(); while (true){ Date now =new Date();//当前时间 long b =now.getTime(); //时间差 long c = a-b; //倒计时提示 System.out.println("剩余"+c/1000+"秒"); //是否是否时间到了 if(c<=0){ System.out.println("时间到了,关机"); Runtime runtime= Runtime.getRuntime();//Runtion是计算机环境,getRuntion()获取环境对象 runtime.exec("shutdown -s -t 60 -f");//执行计算机命令 break; } //休眠 Thread.sleep(1000); } } }
倒计时关机
最新推荐文章于 2024-10-14 00:00:00 发布