Class NtpClient

java.lang.Object
uno.xifan.id.generator.util.time.NtpClient

public class NtpClient extends Object
NTP协议客户端实现

支持RFC 5905规范,提供毫秒级时间同步

  • Constructor Details

    • NtpClient

      public NtpClient()
  • Method Details

    • getTime

      public static Instant getTime(String server) throws Exception
      从NTP服务器获取当前时间
      Parameters:
      server - 服务器地址
      Returns:
      校准后的Instant时间对象
      Throws:
      Exception - 网络或协议异常
    • getTimeWithOffset

      public static OffsetDateTime getTimeWithOffset(String server, ZoneOffset offset) throws Exception
      获取带时区偏移的时间(适用于需要本地时间转换的场景)
      Throws:
      Exception
    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception