http://javajeff.mb.ca/aa/9/9.htmlNice tutorial. I followed most of it, and ended up with this:
public class Uptime
{
// Import kernel32.dll
static
{
try
{
System.loadLibrary("kernel32");
}
catch (UnsatisfiedLinkError e)
{
System.err.println("Unable to load kernel32.dll.");
System.err.println("Are you sure you're using Windows?");
}
}
// Win32.dll imports
public static native int GetTickCount();
// ----
public static void main(String args[])
{
int miliseconds = GetTickCount();
int days, hours, minutes, seconds;
// Copy/pasted from C++ uptime project
seconds = miliseconds / (1000); seconds = seconds % 60;
minutes = miliseconds / (1000 * 60); minutes = minutes % 60;
hours = miliseconds / (1000 * 60 * 60); hours = hours % 24;
days = miliseconds / (1000 * 60 * 60 * 24);
miliseconds = miliseconds % 100;
System.out.println("System uptime: " + days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + "." + miliseconds + " seconds.");
}
}
But then I realized that kernel32's GetTickCount is an INT, not a JINT, and needs to be wrapped (hence Win32.dll instead of Kernel32.dll). Not having a C compiler, nor any C knowledge, I had a hard time wrapping it (in fact, I didn't do it). Might be worth checking out.