将 java.util.Date 对象转换为 Windows FILETIME 结构

发布于 2024-09-14 02:04:37 字数 173 浏览 4 评论 0原文

我有一个 Java 应用程序,需要使用 JNA 调用 Windows DLL。我需要调用的函数实际上采用 __int64 (在内部它将其分为 FILETIME 结构的低/高部分)。给定一个 java.util.Date 对象,如何将其转换为针对 FILETIME 格式化的适当值?

I have a Java application and I need to call into a Windows DLL using JNA. The function I need to call actually takes a __int64 (internally it splits this into low/high portions of the FILETIME structure). Given a java.util.Date object, how can I convert it to the appropriate value formatted for a FILETIME?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梅窗月明清似水 2024-09-21 02:04:37

这是使用 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));

This is 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));
彩扇题诗 2024-09-21 02:04:37

JNA 在 FILETIME< 上提供了一些静态方法/a> 类位于 Platform jar 中。

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

JNA provides some static methods on the FILETIME class which is located in the Platform jar.

FILETIME.dateToFileTime( Date date );
FILETIME.filetimeToDate( int high, int low );
往日情怀 2024-09-21 02:04:37

好吧,我想我已经明白了:

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

Ok, I think I figured it out:

long date = (new Date().getTime() + 11644473600000L) * 10000L;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文