时间戳的引入主要是为了防止_电脑uuid怎么获取

时间戳的引入主要是为了防止_电脑uuid怎么获取Inourjavaapplicationwearetryingtogettheunixtimefromthetype1uuid.Butitsnotgivingthecorrectdatetimevalues.longtime=uuid.timestamp();time=time/10000L;//Dividingby10^4a…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

时间戳的引入主要是为了防止_电脑uuid怎么获取

In our java application we are trying to get the unix time from the type 1 uuid.

But its not giving the correct date time values.

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();

Can some one please help ?

Edit: Fixed the divisor(10^4)

解决方案

From the docs for timestamp():

The resulting timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC.

So you need to offset it from that. For example:

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/169195.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号