Would it be possible to set system time with milliseconds component on Windows OS using Java? I am trying to synchronize clocks between couple of computers but the OS API seems to offer only set time in format: HH:MM:SS.
This is what i tried:
public static void main(String[] args) throws InterruptedException, IOException { String time="10:00:20"; // this works String timeWithMiliseconds = "10:00:20.100"; // this doesn't change time at all Runtime rt = Runtime.getRuntime(); rt.exec("cmd /C time " + time); } I am wondering how do NTP clients work if it's not possible to set milliseconds component ?
One way to deal with this issue could be to calculate time in milliseconds when server should reach next second, and sleep for that time. Is there a better, more direct way to achieve this ?
Runtimethat allows to set time in ms precision