Thi*_*esh 3 java uuid unix-timestamp
在我们的java应用程序中,我们试图从类型1 uuid获取unix时间.但它没有给出正确的日期时间值.
long time = uuid.timestamp();
time = time / 10000L; // Dividing by 10^4 as its in 100 nanoseconds precision
Calendar c = Calendar.getInstance();
c.setTimeInMillis(time);
c.getTime();
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
编辑:修正了除数(10 ^ 4)
Jon*_*eet 11
来自以下文档timestamp():
从UTC时间1582年10月15日午夜开始,生成的时间戳以100纳秒为单位进行测量.
所以你需要从中抵消它.例如:
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
Run Code Online (Sandbox Code Playgroud)