java 修改系统时间

  1. /**  
  2.  * @author crane.ding  
  3.  * @version 1.0 2009-3-26  
  4.  */  
  5.   
  6. //Operating system name   
  7. String osName = System.getProperty("os.name");   
  8. String cmd = "";   
  9. try {   
  10.     if (osName.matches("^(?i)Windows.*$")) {// Window 系统   
  11.     // 格式 HH:mm:ss   
  12.     cmd = "  cmd /c time 22:35:00";   
  13.     Runtime.getRuntime().exec(cmd);   
  14.     // 格式:yyyy-MM-dd   
  15.     cmd = " cmd /c date 2009-03-26";   
  16.     Runtime.getRuntime().exec(cmd);   
  17. else {// Linux 系统   
  18.    // 格式:yyyyMMdd   
  19.    cmd = "  date -s 20090326";   
  20.    Runtime.getRuntime().exec(cmd);   
  21.    // 格式 HH:mm:ss   
  22.    cmd = "  date -s 22:35:00";   
  23.    Runtime.getRuntime().exec(cmd);   
  24. }   
  25. catch (IOException e) {   
  26.     e.printStackTrace();   
  27. }  

你可能感兴趣的:(java,linux,windows,OS,idea)