Java library for dealing with win32 FILETIME?

前端 未结 3 743
鱼传尺愫
鱼传尺愫 2021-02-06 11:28

Are there any Java libraries around for dealing with the win32 FILETIME/ time intervals ? It\'s basically a 64 bit timestamp in 100ns intervals since January 1, 1601.

(

3条回答
  •  悲哀的现实
    2021-02-06 11:44

    If you are fine with millisecond resolution, this would work:

    /** Difference between Filetime epoch and Unix epoch (in ms). */
    private static final long FILETIME_EPOCH_DIFF = 11644473600000L;
    
    /** One millisecond expressed in units of 100s of nanoseconds. */
    private static final long FILETIME_ONE_MILLISECOND = 10 * 1000;
    
    public static long filetimeToMillis(final long filetime) {
        return (filetime / FILETIME_ONE_MILLISECOND) - FILETIME_EPOCH_DIFF;
    }
    
    public static long millisToFiletime(final long millis) {
        return (millis + FILETIME_EPOCH_DIFF) * FILETIME_ONE_MILLISECOND;
    }
    

    At this point, converting from ms to a Date object is quite straightforward.

提交回复
热议问题