How do you represent MS-DTYP `DATETIME` in Java 8 Instant?

前端 未结 2 1350
面向向阳花
面向向阳花 2021-01-22 11:19

In the Microsoft Spec, DATETIME is represented as 2 32-bit integers: low and high

Reference: https://docs.microsoft.com/en-us/open

2条回答
  •  执笔经年
    2021-01-22 12:07

    Ah I was barking up the wrong tree when I split the bytes in half like that.

    Basically it's just saying that the units are in 100ns.

    And the Epoch has a different base time too. So you have to add the offset as well.

    So it is:

        private static final long DATETIME_EPOCH_DIFF_1601;
        static {
            LocalDateTime time32Epoch1601 = LocalDateTime.of(1601, Month.JANUARY, 1, 0, 0);
            Instant instant = time32Epoch1601.atZone(ZoneOffset.UTC).toInstant();
            DATETIME_EPOCH_DIFF_1601 = (instant.toEpochMilli() - Instant.EPOCH.toEpochMilli()) / 1000;
        }
        Instant answer = Instant.ofEpochSecond(fullval / 10000000 + DATETIME_EPOCH_DIFF_1601)
    

提交回复
热议问题