windowstime.java
来自「本次实验中用Java实现的Calendar具有跨平台运行能力」· Java 代码 · 共 49 行
JAVA
49 行
package edu.swjtu.sist.java.calendar;
/**
* 该类通过本地方法private static native boolean setTime(int year, int month, int day, int hour, int min, int sec);
* 来将应用程序的修改后的时间应用为真实的系统时间。
*
* 需要使用JNI分别实现windows下的*.DLL,和linux下的*.SO
*
* @author 518lee@gmail.com
* @version 1.0
*/
public class WindowsTime
{
public WindowsTime()
{
}
public static boolean hasModified=false;
private static native boolean setTime(int year, int month, int day, int hour, int min, int sec);
public static void setLocalTime(int year, int month, int day, int hour, int min, int sec)
throws TimeOutException
{
if(year < 1980)
throw new TimeOutException("year");
if((month < 0) | (month > 12))
throw new TimeOutException("month");
if((day < 1) | (day > 31))
throw new TimeOutException("day");
if((hour < 0) | (hour > 23))
throw new TimeOutException("hour");
if((min < 0) | (min > 59))
throw new TimeOutException("minutes");
if((sec < 0) | (sec > 59))
throw new TimeOutException("seconds");
if(!setTime(year, month, day, hour, min, sec))
throw new TimeOutException("All");
else
return;
}
static
{
System.loadLibrary("SetSysTime");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?