File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I set System time?

 
Vasudhaiv Naresh
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I would like to know if there's any way to set the system time using java, just as we can get the system time using
.
Please let me know how I can set the system time or atleast whether it is possible or not.
Regards,
Naresh
 
Virag Saksena
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java gets the system time from the underlying operating system
On most systems, setting time requires superuser privileges,
so you cannot do it from vanilla Java.

To do this essentially will require you to
#1. Create a native library to do setuid to become superuser
#2. Call settimeofday (or equivalent system call)
#3. Create a java wrapper to expose this as a java call

Doing this creates inherent security risks and breaks normal Java conventions and is not recommended.

What are you trying to do which requires you to set the system time from Java ?
 
Don Morgan
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An alternative to JNI would be to try use the java runtime to exec whatever command is appropriate to the system you are using.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic