在java中如何更改或者设置系统时间????????

解决方案 »

  1.   

    try {
        java.lang.Runtime.getRuntime().exec("cmd /c time 22:10:44");
        } catch (java.io.IOException e) 
        {
        e.printStackTrace();           
        }
      

  2.   

    上面那个错了,不要cmdRuntime.getRuntime().exec("date 2000-12-20");
      

  3.   

    --->用java.util.Calandar类
    早试过了,不行,取得时间还行,设置或改动是不行的.....
      

  4.   

    那你只有自己写jni调用了,但还是不能跨平台,
      

  5.   

    哎,郁闷,java如此强大,竟然连这样一个小问题都没法解决,可笑..........
    去其他论坛问问了....先谢谢大家了.....过会看看有没有答案,没有也到时揭贴,给分...
      

  6.   

    先用(String)System.getProperties().get("os.name"))得到系统名称
    在根据不同的系统用java.lang.Runtime.getRuntime().exec执行不同的更改时间的命令
      

  7.   

    String osname = System.getProperty("os.name"); 
    if (osname.indexOf("NT") > -1) 
              command =SystemDisk+"\\winnt\\System32\\cmd.exe";
      else if(osname.equals("Windows XP"))
              command =SystemDisk+"\\WINDOWS\\System32\\cmd.exe";
      else if(osname.equals("Windows 2000"))
              command =SystemDisk+"\\WINNT\\system32\\cmd.exe";
      else  if(osname.equals("Windows 98")) 
              command =SystemDisk+"\\Windows\\command.com";
     Process process=Runtime.getRuntime().exec(command + " /c "+commandString); 
    InputStream inStr = process.getInputStream(); 
    BufferedReader bufRead = new BufferedReader(new InputStreamReader(inStr));
    String string; 
    while ((string =bufRead.readLine()) != null) 
    System.out.println(string);
    哎,好麻烦........
      

  8.   

    操作系统版本不计其数,if else能解决的了么?