0

Possible Duplicate:
How can I set the System Time in Java?

I want to set the system time from a Java program. I've been googling and the only solution I found involves Runtime.exec. This has the really fat disadvantage that Windows also has no reasonable system command to set the system time (e.g. how do I get the date locale?).

I am now using winapi through jna. This is fun (no irony).

Now I wondered if no one ever bothered to make an OS independent Java library to set the system time. The question seems to come up often enough.

17
  • 1
    It's probably because no one except OS-provided tools usually need to set the system time. Commented Oct 10, 2012 at 7:49
  • 1
    This is a command that changes the OS behavior, and you don't want any Java program to escalate until the admin privileges so easily. Due to this security reason, I guess you won't have another option. Commented Oct 10, 2012 at 7:49
  • 1
    @Thilo: I disagree. Deleting files can be a pretty common operation for a Java application. Just think about deleting temporary files. Also: OS already have a good mechanism for allowing processes to delete some files while keeping others safe. Those mechanisms don't usually exist for the system time (which is a global settings in all OS I know of). Commented Oct 10, 2012 at 7:52
  • 1
    "The question seems to come up often enough." - Don't confuse this with some indication of real demand. Basically, you would be hard pressed to find a genuine need to be able to set the clock portably from Java. (And some guy at home thinks it would be cool does not count as genuine need in my books.) Commented Oct 10, 2012 at 7:57
  • 2
    @peter: "exact duplicate" means that you're asking for the same thing. it does not necessarily mean that the other question has an answer that you'd find helpful (but that would be a good bonus, of course). Commented Oct 10, 2012 at 8:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.