//Operating system name
String osName = System.getProperty("os.name");
String cmd = "";
try {
if (osName.matches("^(?i)Windows.*$")) {// Window 系统
// 格式 HH:mm:ss
cmd = " cmd /c time 22:35:00";
Runtime.getRuntime().exec(cmd);
// 格式:yyyy-MM-dd
cmd = " cmd /c date 2009-03-26";
Runtime.getRuntime().exec(cmd);
} else {// Linux 系统
// 格式:yyyyMMdd
cmd = " date -s 20090326";
Runtime.getRuntime().exec(cmd);
// 格式 HH:mm:ss
cmd = " date -s 22:35:00";
Runtime.getRuntime().exec(cmd);
}
} catch (IOException e) {
e.printStackTrace();
}
国家授时中心API:
http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json