Results 1 to 3 of 3

Thread: System attributes

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    In java, is it possible to access and/or edit system attributes like the system date/time?

    If so, how?

  2. #2
    Guest

    Thumbs up java.util.Calendar

    Code:
    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.

  3. #3
    Guest

    Thumbs down It failed verification by the desktop clock

    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.
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width