Convert java.util.Date object to Windows FILETIME structure

I have a Java application and I need to call the Windows DLL using JNA. The function I need to call accepts __int64(internally, it divides it into low / high parts of the structure FILETIME). Given an object java.util.Date, how can I convert it to the corresponding value formatted for FILETIME?

+3
source share
3 answers

JNA provides some static methods in the FILETIME class , which is located in the Platform bank.

FILETIME.dateToFileTime( Date date );
FILETIME.filetimeToDate( int high, int low );
+2
source

Here's how you can do it using Java nio

    BasicFileAttributes attr = Files.readAttributes(filePath, BasicFileAttributes.class);
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    Date d = new Date(attr.creationTime().toMillis()); //attr.creationTime() returns a FileTime             
    System.out.println(df.format(d));
+5

, , :

long date = (new Date().getTime() + 11644473600000L) * 10000L;
+1

Source: https://habr.com/ru/post/1759159/


All Articles