問題描述
Java - 從外部服務器獲取 POSIX UTC 時間戳的最佳選擇? (Java - Best choice to get a POSIX UTC timestamp from external server?)
I have a Java program that needs the current date and time. This is normally easily done, but if the user's system date/time is incorrectly set it could present issues for my software.
I want to pull the current date/time from an external server, so I was thinking I could use a Java implementation of an NTP client to pull a POSIX UTC timestamp from a public NTP server (e.g. pool.ntp.org) as that's way more dependable and cost effective than me running my own server(s) for this purpose.
Is NTP a good solution here, or is there a better protocol that I'm unaware of?
參考解法
方法 1:
I've used apache commons NTP before which is fine, unless you're running on windows and need millisecond accuracy, in which case, read this answer.
(by Salis、Steve Atkinson)