我如何在Java中将此十六进制字符串转换为Date [英] How do i get this Hex string converted to Date in java
本文介绍了我如何在Java中将此十六进制字符串转换为Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试转换十六进制字符串 07e4070e04032b
到目前为止,以下是我的代码:
I am trying to convert hex string "07e4070e04032b
" to date and below is my code:
String hexmillis1 = "07e4070e04032b";
long convertedMillis1 = Long.decode("0x" + hexmillis1);
Instant instant1 = Instant.ofEpochMilli(convertedMillis1);
LocalDateTime localDateTime1 = LocalDateTime.ofInstant(instant1, ZoneId.systemDefault());
System.out.println(localDateTime1.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
输出: + 72352-01-29T13:17:02.571
预期的输出是今天早些时候的日期和时间,所以2020-07-14或2020-07-13。
Expected output is a date and time earlier today, so 2020-07-14 or perhaps 2020-07-13.
我很少尝试
十六进制字符串来自SNMP陷阱。不确定如何正确编码。
The hex string is coming from a SNMP trap. Not sure of how it was exactly encoded.
推荐答案
您可以看到此处转换正确。
十六进制值有问题:
07e4070e04032b == 2221043788022571
这篇关于我如何在Java中将此十六进制字符串转换为Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文