如果我想转换使用Java在Windows中重现时间的64位数字,我该怎么做?
该号码是129407978957060010
我对如何让它发挥作用感到非常困惑。数学从来不是我的事情:))
非常感谢
答案 0 :(得分:15)
该时间可能代表自Jan 1. 1601以来的100纳秒单位。在1601年和1970年之间有116444736000000000 100ns。
Date date = new Date((129407978957060010-116444736000000000)/10000);
答案 1 :(得分:2)
假设64位值是FILETIME
值,它表示自1601年1月1日以来100纳秒间隔的数量.Java Date
类存储自1月1日以来的毫秒数, 1970.要从前者转换为后者,您可以这样做:
long windowsTime = 129407978957060010; // or whatever time you have
long javaTime = windowsTime / 10000 // convert 100-nanosecond intervals to milliseconds
- 11644473600000; // offset milliseconds from Jan 1, 1601 to Jan 1, 1970
Date date = new Date(javaTime);
答案 2 :(得分:1)
Java使用Unix Timestamp。您可以使用online converter查看当地时间。
在java中使用它:
Date date = new Date(timestamp);
<强>更新强>
似乎在Windows上他们有different time offset。因此,在Windows机器上,您将使用此计算转换为Unix时间戳:
#include <winbase.h>
#include <winnt.h>
#include <time.h>
void UnixTimeToFileTime(time_t t, LPFILETIME pft)
{
// Note that LONGLONG is a 64-bit value
LONGLONG ll;
ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD)ll;
pft->dwHighDateTime = ll >> 32;
}
答案 3 :(得分:0)
public static void main(String as []){
String windowNTTimeStr = "131007981071882420";
String finalDate = "";
try {
//Windows NT time is specified as the number of 100 nanosecond intervals since January 1, 1601.
//UNIX time is specified as the number of seconds since January 1, 1970. There are 134,774 days (or 11,644,473,600 seconds) between these dates.
//NT to Unix : Divide by 10,000,000 and subtract 11,644,473,600.
//Unix to NT : Add 11,644,473,600 and multiply by 10,000,000
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Long windowsTime = Long.parseLong(windowNTTimeStr);
long javaTime = windowsTime / 10000 - 11644473600000L;
Date date = new Date(javaTime);
Calendar c = Calendar.getInstance();
c.setTime(new Date(javaTime));
Calendar cCurrent = Calendar.getInstance();
cCurrent.setTime(new Date());
cCurrent.add(Calendar.YEAR, 100);
if (!(c.getTime().getYear() > cCurrent.getTime().getYear())) {
finalDate = sdf.format(c.getTime());
}
} catch (Exception e) {
finalDate = null;
}
System.out.println(" Final Date is "+finalDate);
} //Expected out put Final Date is 2016-02-24 20:05:07
答案 4 :(得分:-1)
我认为时间是一个很长的数字。
Date temp = new Date();
temp.setTime((129407978957060010-116444736000000000)/10000);
setTime会添加自1970年1月1日以来long所代表的所有毫秒数。