Set the computer clockTag(s): Date and Time JNI
Define the following prototype in the header file
JNIEXPORT void JNICALL Java_JavaHowTo_setSystemTime (JNIEnv *, jobject, jshort, jshort);
JNIEXPORT void JNICALL Java_JavaHowTo_setSystemTime
(JNIEnv *env, jobject obj, jshort hour, jshort minutes) {
SYSTEMTIME st;
GetLocalTime(&st);
st.wHour = hour;
st.wMinute = minutes;
SetLocalTime(&st);
}class JavaHowTo {
public native void setSystemTime( short hour, short minutes);
static {
System.loadLibrary("javahowto");
}
}public class JNIJavaHowTo {
public static void main(String[] args) {
short hour = 10;
short minutes = 21;
// this example will set the system at 10h21 using the Windows API
// SetLocalTime.
JavaHowTo jht = new JavaHowTo();
// set the time at 10h21
jht.setSystemTime(hour, minutes);
}
}
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com