一个简单而又复杂的问题,郁闷。。。。。。。(谁给解决了,马上给50分!) 在java中如何更改或者设置系统时间???????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try { java.lang.Runtime.getRuntime().exec("cmd /c time 22:10:44"); } catch (java.io.IOException e) { e.printStackTrace(); } 上面那个错了,不要cmdRuntime.getRuntime().exec("date 2000-12-20"); --->用java.util.Calandar类早试过了,不行,取得时间还行,设置或改动是不行的..... 那你只有自己写jni调用了,但还是不能跨平台, 哎,郁闷,java如此强大,竟然连这样一个小问题都没法解决,可笑..........去其他论坛问问了....先谢谢大家了.....过会看看有没有答案,没有也到时揭贴,给分... 先用(String)System.getProperties().get("os.name"))得到系统名称在根据不同的系统用java.lang.Runtime.getRuntime().exec执行不同的更改时间的命令 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);哎,好麻烦........ 操作系统版本不计其数,if else能解决的了么? 多线程之生产者消费者 java可以做模式识别吗?为什么好像国内没人用java搞模式识别啊? 帮忙看看错 OutOfMemoryError 异常Out of swap space 正则表达式匹配问题 为什么我的程序中calendar.get(Calendar.YEAR)得到的年份总是错误的啊! 请问一个有关JTable的问题 软件设计思想 java.swing.timer怎么用? 有谁知道JBuilder 7的注册码?? 变量传递的问题 求助:检索PDF文件并打印的问题?
java.lang.Runtime.getRuntime().exec("cmd /c time 22:10:44");
} catch (java.io.IOException e)
{
e.printStackTrace();
}
早试过了,不行,取得时间还行,设置或改动是不行的.....
去其他论坛问问了....先谢谢大家了.....过会看看有没有答案,没有也到时揭贴,给分...
在根据不同的系统用java.lang.Runtime.getRuntime().exec执行不同的更改时间的命令
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);
哎,好麻烦........