TOD 时钟时间为 java.util.Date 或毫秒

2024-02-28

我有一个数据库表,其中填充了通过 ETL 来自大型机的数据。 该表的一列称为“TOD”,如“Time-Of-Day”中的“TOD”。

该列存储诸如以下的值: “CAE7631DC43DC686” “CAE7631C4AC6DC0B” “CAE6216DF2BC0D04” “CAE621D8F9916E8E”

所有这些值都是在2013年2月10日和2013年2月11日左右。 现在,在大型机上,这是时间-日期表示(TOD 时钟)。

它表示从 1900 年 1 月 1 日起过去的时间,以宏秒(1/1 000 000 秒)为单位。

我需要的是一个java库/方法/算法实现,可以将这些字符串转换为java.util.Date。

在网上找到了这些网站:http://paul.saers.com/Tod_howto.html http://paul.saers.com/Tod_howto.html http://www.longpelaexpertise.com.au/toolsTOD.php http://www.longpelaexpertise.com.au/toolsTOD.php

本页解释了如何计算它,但对我来说有点太多了。 我确信我会在某个地方犯一些错误。

所以,我的问题是;你知道我可以使用的图书馆(Joda Time?)吗? 我需要将这些值转换为 java.util.Date 并将 Date 对象转换为字符串表示形式(如“CAE621D8F9916E8E”)。

提前致谢。


在我的用例中,我有一个 getter 方法,可以直接将 8 字节 TOD 作为字节数组读取,并将其转换为 long,但这里要遵循海报:

BigInteger bi = new BigInteger    ("CAE7631DC43DC686", 16); //  no strip off of 686 
long tod = bi2.longValue();

我使用以下方法来避免 BigDecimal 计算开销:

tod = tod >>> 12;  // remove rightmost 3 bytes and replace with zeros
tod = tod - 2208988800000000l;  // substract 1970
tod = tod/1000; // make millis out of micros
// timeformatter and dateformatter without Joda
SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss.SS z Z", Locale.getDefault());
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy", Locale.getDefault());
// Display
System.out.println(timeFormatter.format(new Date(tod)));
System.out.println(dateFormatter.format(new Date(tod)));

输出将是:

欧洲中部时间 22:59:46.420 +0100

2013年2月10日

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TOD 时钟时间为 java.util.Date 或毫秒 的相关文章

随机推荐