在我们的Java应用程序中,我们尝试从UUID version 1获取UNIX时间。但是它没有给出正确的日期时间值。
long time = uuid.timestamp();
time = time / 10000L; // Dividing by 10^4 as it's in 100 nanoseconds precision
Calendar c = Calendar.getInstance();
c.setTimeInMillis(time);
c.getTime();
有人可以帮忙吗? 最佳答案
从timestamp()
的文档中:
因此,您需要从中弥补它。例如:
Calendar uuidEpoch = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
uuidEpoch.clear();
uuidEpoch.set(1582, 9, 15, 0, 0, 0); // 9 = October
long epochMillis = uuidEpoch.getTime().getTime();
long time = (uuid.timestamp() / 10000L) + epochMillis;
// Rest of code as before
关于java - 从UUID版本1获取UNIX时间戳。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13070674/