Click to See Complete Forum and Search --> : System attributes
wey97
Feb 8th, 2001, 04:37 PM
In java, is it possible to access and/or edit system attributes like the system date/time?
If so, how?
import java.util.*;
public class Sys{
public static void main(String[] args){
Calendar c = Calendar.getInstance();
Calendar savedCal = c; // Saved to reset the system calendar later
Date currentDate = c.getTime();
System.out.println("Current: " + currentDate); // The current date/time
System.out.println("Saved : " + savedCal.getTime()); // The current date/time
c.set(Calendar.YEAR, 2525);
currentDate = c.getTime(); // The current date/time AFTER MODIFICATION
System.out.println("Current: " + currentDate); // The current date/time AFTER MODIFICATION
c.setTime(savedCal.getTime()); // Restore the correct date/time (losing time during run of
program)
Calendar restoredCal = Calendar.getInstance();
currentDate = restoredCal.getTime();
System.out.println("Current: " + currentDate); // The current date/time
}
}
Notice the year was changed to 2525, then changed back to the correct time (except for error in the time it took to run the program).
I'm going to write a serialized Calendar object to disk and check if the system time was really changed by looking at the desktop clock. Then I'll load the saved Calendar from disk to reset the system date/time. I'd expect that to work if I really am changing system properties.
Sorry, no solution yet
This would seem like the right track, but it didn't change my desktop clock.
I saved the calendar to disk (for later retrieval), and only used the code to change the year to 2525. But since the desktop clock didn't change, I didn't have to use the saved one to restore it.
I was hoping that the desktop clock would change, then I'd reload the saved calendar from disk and reset the system clock. :(
The following also failed:
Runtime.getRuntime().exec("date 12-25-30");
Runtime.getRuntime().exec("time 10:00:00");
although they work on the command line.
The date one had Y2K issues anyway.
Possibly you can try to stream to the Process created by "exec" and have the date set by responding to prompts (since it may be the StringTokenizer that is screwing up "exec").
If you find out how to do it, let me know.
Virtually_Dwight@hotmail.com
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.