需要调用jni本地资源
package com.lyc.jni;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ChangSystemTime extends Thread {
/**
* 改变操作系统时间
* @param increaseTime 增加的时间单位为秒
* @param waitTime 需要等待的时间
*/
public void changTime(int increaseTime,int waitTime) {
SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
System.out.println("现在时间为:" + sf.format(date));
date.setTime(System.currentTimeMillis() + increaseTime * 1000);
String fd = sf.format(date);
String c = "time " + fd;
try {
Runtime.getRuntime().exec("cmd.exe /c " + c);
Thread.sleep(waitTime*1000);
} catch (Exception e) {
e.printStackTrace();
}
Date ndate = new Date(System.currentTimeMillis());
System.out.println("执行成功,现在时间为:" + sf.format(ndate));
}
/**
*
* @param increaseTime 增加的时间单位为秒
* @param waitTime 需要等待的时间
* @param times 循环的次数
*/
public void changTimecircled(int increaseTime,int waitTime,int times){
for (int i = 0; i < times; i++) {
changTime(increaseTime, waitTime);
}
}
}