本文介绍了TOD时钟时间为java.util.Date或毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库表,该表通过ETL填充了来自大型机的数据。
该表的一列在每日时间中称为 TOD。

I have a database table, which is filled with data from a mainframe via ETL.One column of that table is called "TOD" as in Time-Of-Day.

此列存储的值包括:
CAE7631DC43DC686
CAE7631C4AC6DC0B
CAE6216DF2BC0D04
CAE621D8F9916E8E

This columns stores values such as :"CAE7631DC43DC686""CAE7631C4AC6DC0B""CAE6216DF2BC0D04""CAE621D8F9916E8E"

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

all these values are around Feb 10th 2013 and Feb 11th 2013.now, on mainframe, this is a time-date representation (TOD clock).

它表示从01.01.1900开始经过的时间(以毫秒为单位)(1 / 1 000 000秒)。

it represents the time past from 01.01.1900 in macroseconds (1/1 000 000 of a second).

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

What I need is a java library / method / algorithm implementation that could convert these strings to java.util.Date's.

在网络上找到了以下网站:

Found these sites on the web :http://paul.saers.com/Tod_howto.htmlhttp://www.longpelaexpertise.com.au/toolsTOD.php

此页说明了如何计算,但对我来说有点太多了。
我确定我会在某些地方出错。

This page explains how to calculate it, but it's a little too much for me.I'm sure I'd do some errors somewhere.

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

So, my question is; do you know about a library (Joda Time ?) that I could use ?I need to convert these value to a java.util.Date and a Date object to a string representation, (like "CAE621D8F9916E8E").

推荐答案

使用Joda逐步进行操作:

Step by step, using Joda:

数据可以在您所引用的网站上 指出TOD以UTC表示

Data used in the calculation can be found on the website you referred to The other reference you gave states that TOD is expressed in UTC

// we start with your string minus the three last digits
// which are some internal z/Series cruft
BigInteger bi = new BigInteger    ("CAE7631DC43DC", 16); // 686 stripped off
// then, from tables the website we get the TOD value for start of epoch
// here also, minus the three last digits
BigInteger startOfEpoch70 = new BigInteger ("7D91048BCA000", 16); // 000 stripped off
// using that we calculate the offset in microseconds in epoch
BigInteger microsinepoch = bi.subtract(startOfEpoch70);
// and reduce to millis
BigInteger millisinepoch = microsinepoch.divide(new BigInteger("1000"));
// which we convert to a long to feed to Joda
long millisinepochLong = millisinepoch.longValue();
// Et voila, the result in UTC
DateTime result = new DateTime(millisinepochLong).withZone(DateTimeZone.UTC);
// Now, if you want a result in some other timezone, that's equally easy
// with Joda:
DateTime result2 = result.toDateTime(DateTimeZone.forID("EET"));

System.out.println("The result is " + result + " or represented in timezone EET "
                   + result2);

输出如下:

我所指的素材解释如下:

The "cruft" I refer to is explained as follows:

当然,除了残酷地从字符串中截取这些字节之外,还可以这样做

Of course, instead of brutally snipping these bytes off the string, one could also do

bi = bi.divide(new BigInteger("1000", 16));

除以十六进制1000也会删除最后12位。

as dividing by hex 1000 will also get rid of the last 12 bits.

编辑:正如Mehmet在评论中指出的那样,TOD为UTC,这意味着应告知生成的DateTime。为了方便起见,我还展示了如何将DateTime转换为另一个时区(以 EET 为例)

as Mehmet pointed out in the comments, TOD is in UTC and this means that the resulting DateTime should be told so. For convenience I also showed how to transpose that DateTime to another time zone (using EET as an example)

这篇关于TOD时钟时间为java.util.Date或毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 05:32