• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

How do I set System time?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic