Java代码修改系统时间,windows,Linux,Solaris,需要用超级管理员账号登陆系统


 //Operation System Name;
            String osName = System.getProperty("os.name");
            if(osName.matches("^(?i)Windows.*$"))
            {
                Runtime.getRuntime().exec("cmd /c date " + year + "-" + month + "-" + day);
                Runtime.getRuntime().exec("cmd /c time " + hours + ":" + minutes + ":" + seconds);
            }
            else//linux or solaris;
            {
                //date 091815302010.59  , 9月18日 15点30分 2010年,59秒 ,
                Runtime.getRuntime().exec("date "+month+day+hours+minutes+year+"."+seconds);
            }  







  // date 091815302010.59 , 9月18日 15点30分 2010年,59秒 ,
        String strMonth = month < 10 ? "0" + month : "" + month;
        String strDay = day < 10 ? "0" + day : "" + day;
        String strHours = hours < 10 ? "0" + hours : "" + hours;
        String strMinutes = minutes < 10 ? "0" + minutes : "" + minutes;
        String strSeconds = seconds < 10 ? "0" + seconds : "" + seconds;
        Runtime.getRuntime().exec("date " + strMonth + strDay + strHours + strMinutes + year + "." + strSeconds);
     



//Java代码修改系统时间,windows,Linux,Solaris,需要用超级管理员账号登陆系统

猜你喜欢

转载自gmleegmlee.iteye.com/blog/1335642