System.currentTimeMillis() 可以读取本机系统时间,但是怎么设置本机系统时间呢?
如果一定要用到本地方法的话,能否请大家留下 windows 和 linux 下的 C 代码,非常感谢!

解决方案 »

  1.   

    http://topic.csdn.net/t/20041009/19/3438422.html
    这也要给分吧
      

  2.   

    linux的系统时间可以设定的吧,windows估计要调用MS API才能实现
      

  3.   

    windows:
    java.lang.Runtime.getRuntime().exec("cmd   /c   time   10:15:25");
    Linux:
    java.lang.Runtime.getRuntime().exec("date 10:15:25");
      

  4.   

    JAVA API好像没有提供相应的方法
    你用 ll42002(灰舌) 的方法
      

  5.   

    if (osName.indexOf("win") != -1) {
    String command1 = "cmd /c date " + year + "-" + month + "-"+ day;
    String command2 = "cmd /c time " + hour + ":" + minute + ":" + second;
    try {
       Process p = Runtime.getRuntime().exec(command1);
       p.waitFor();
       p.destroy();
       Process q = Runtime.getRuntime().exec(command2);
       q.waitFor();
       q.destroy();
    } catch (Exception e) {
    e.printStackTrace();
    }

    if (linux操作系统) {
       String[] linuxDateCmd = { "/bin/sh", "-c","date -s " + month + "/" + day + "/" + year };
       String[] linuxTimeCmd = { "/bin/sh", "-c", "date -s " + hour + ":" + minute + ":" + second };
    try {
       Process p = Runtime.getRuntime().exec(linuxDateCmd);
       p.waitFor();
       p.destroy();
       Process q = Runtime.getRuntime().exec(linuxTimeCmd);
       q.waitFor();
       q.destroy();
    } catch (Exception e) {
       e.printStackTrace();
    }
    }
      

  6.   

    本机时间:
      java.util.Date date=new java.util.Date();
      System.out.println("得到当前时间");
      String sdate=new java.text.SimpleDateFormat("yyyy-MM-dd").fromat(date);
      System.out.println("这是格式化后的当前日期时间");
     当然,还可以有其他的方法
      

  7.   

    一,调用系统命令
    windows:cmd   /c   time   10:15:25
    Linux:date 10:15:25
    二, 调用其他JNI 接口
      

  8.   

    同意
    windows:
    java.lang.Runtime.getRuntime().exec("cmd   /c   time   10:15:25");
    Linux:
    java.lang.Runtime.getRuntime().exec("date 10:15:25");