package com.hp.demo05; import java.util.Date; public class Demo02 { public static void main(String[] args) throws Exception{ int s = 60; //60秒后的时间 Date mb = new Date(); mb.setMinutes(mb.getMinutes()+1);//原有分钟+1900 long a = mb.getTime(); while (true) { Date now = new Date();//当前时间 long b = now.getTime();// long c = a-b; if (c==0){ System.out.println("时间到了,开始关机..."); Runtime runtime = Runtime.getRuntime(); runtime.exec("shutdown -s -t 60 -f"); break; } System.out.println("剩余"+c/1000+"秒关机"); Thread.sleep(1000); } } }
倒计时关机案例
于 2022-07-14 16:36:44 首次发布