java简单实现定时关机

import org.apache.commons.lang3.time.DateUtils;
import java.util.Date;

public class CMDUtil {

    public static void main(String[] args) {
        try {
            Date date = DateUtils.parseDate("2019-11-07 21:00:00", "YYYY-MM-dd HH:mm:ss");
            while (date.getTime() > new Date().getTime()) {
            }
            System.out.println("关机");
            Process exec = Runtime.getRuntime().exec("shutdown -s -t 0");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(拔出萝卜带出坑,定时关机)