我正在使用代理Java應用程序,它安裝在世界不同地方的幾臺Windows機器上。我想定期同步窗口時鐘(日期和時間)。我已經發現了本機命令通過Java代碼來設置窗口時間:由java應用程序在windows機器上設置日期和時間的最佳方式
Runtime.getRuntime().exec("cmd /C date " + strDateToSet); // dd-MM-yy
Runtime.getRuntime().exec("cmd /C time " + strTimeToSet); // hh:mm:ss
或執行
Runtime.getRuntime().exec("cmd /C date " + strDateToSet + "& time " + strTimeToSet);
但主要的問題是focalizied上設定的日期,因爲有可能是日期格式在Windows機器上的所有機器都不一樣。例如,對於意大利機器,我可以有dd-MM-yy,對於美國機器,我可以有yy-MM-dd。所以如果我的應用程序設置日期格式dd-MM-yy對美國機器來說是錯誤的。
知道我cant't使用NTP(機器到局域網防火牆規則出唯一協議HTTPS端口443) 我怎麼能爲所有Windows機器設置正確日期由java應用程序? 哪一個是最好的解決方案semplicity和可維護性?
注意:代理的Java應用程序已經時間戳將Windows機器通過網絡服務響應傳遞設置,因此只做setDateAndTime
與格式日期YYYY TEST EXEC date命令必要-MM-dd在Windows上(設置錯誤的日期):
爲什麼你不能使用NTP?因爲這是(IMO)簡單和可維護性最好的**解決方案。 –
舊學校但:http://stackoverflow.com/a/17035731/180100 – 2017-04-25 15:58:35
可能:https://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html#getDateInstance (int )它使用默認的語言環境。 – assylias