title: Best way to set date and time on windows machine by java application
body: <p>I'm working with an agent java application and it is installed on several Windows machines in different places of the world. I would like periodically synchronize windows clock (Date and Time). I have already found the native command to set time in windows by java code:</p>
  
  <pre><code>Runtime.getRuntime().exec("cmd /C date " + strDateToSet); // dd-MM-yy
  Runtime.getRuntime().exec("cmd /C time " + strTimeToSet); // hh:mm:ss
  </code></pre>
  
  <p>or to execute </p>
  
  <pre><code>Runtime.getRuntime().exec("cmd /C date " + strDateToSet + "&amp; time " + strTimeToSet);
  </code></pre>
  
  <p>But the main problem is focalizied on set date, because is possible that the date format on windows machines is not the same for all machines. For example I could have <strong>dd-MM-yy</strong> for Italian machine and <strong>yy-MM-dd</strong> for US machine. So if my application set the date with format dd-MM-yy wuold be wrong for US machine.</p>
  
  <p>Knowing that I cant't use NTP (Machines into LAN with Firewall with out rules only protocol HTTPS port 443) 
  <strong>how can I set date correctly by java application for all windows machines ?</strong>
  <strong>Which is the best solution both semplicity and maintainability ?</strong>   </p>
  
  <p><strong>Note</strong>: <em>Agent java application has already the timestamp to be set on windows machine passed by web service response, therefore is necessary only to do the setDateAndTime</em>    </p>
  
  <p>TEST exec date command with format date yyyy-MM-dd on Windows (set wrong date):
  <a href="https://i.stack.imgur.com/7FxYu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7FxYu.png" alt="enter image description here"></a></p>