【发布时间】:2012-10-15 18:14:05
【问题描述】:
在我们的 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();
有人可以帮忙吗?
【问题讨论】:
-
你不是除错了数字(
10^8)吗? Timestamp 给出了 100 ns (10^-7 s) 块的数量,因此您需要 10^4 junk 才能获得 1 ms (10^-3 s)。因此,您必须除以 10000L。 -
@Halex 修复了除数。谢谢
标签: java uuid unix-timestamp