NTP 时间戳到 UTC; 32 位无符号秒 + 32 位小数字段

NTP timestamp to UTC; 32 bit unsigned seconds + 32 bit fraction field

T1 = C50204ECEC42EE92

T2 = C50204EBD3E8DDA4

时间戳格式包括作为跨越 136 年的字段的前 32 位无符号秒和解析 232 皮秒的 32 位小数字段。

T1 可以解析为 2004 年 9 月 27 日 03:18:04.922896299 UTC。如何编写程序将 T2 或类似时间转换为 UTC 时间。

public static ZonedDateTime parseNtp(String ts) {
    long seconds = Long.parseLong(ts.substring(0, 8), 16);
    long fraction = Long.parseLong(ts.substring(8), 16);
    return LocalDateTime.parse("1900-01-01T00:00:00").atZone(ZoneId.of("UTC"))
            .plusSeconds(seconds)
            .plusNanos((long)(1000000000.0 / (1L << 32) * fraction));
}

Ideone Demo