java

java time ticks

kimbs0301 2024. 7. 5. 15:43
import java.time.*;

public class JavaTimeTest {
    private static final long TICKS_AT_EPOCH = 621355968000000000L;

    public static void main(String[] args) {
        ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
        long timestampWithNanos = now.toEpochSecond() * 10000000L;
        timestampWithNanos += now.getNano() / 100;
        timestampWithNanos += TICKS_AT_EPOCH;
        System.out.println(timestampWithNanos);

        long tick = System.currentTimeMillis() * 10000L + TICKS_AT_EPOCH;
        System.out.println(tick);

        Instant utcInstant = Clock.systemUTC().instant();
        long ticks = utcInstant.getEpochSecond() * 10000000L;
        ticks += utcInstant.getNano() / 100L;
        ticks += TICKS_AT_EPOCH;
        System.out.println(ticks);
    }
}

 

실행 결과>

더보기
더보기

638556580691874029
638556580691890000
638556580691893973