简体   繁体   English

是否可以在Java中将1970年的基准毫秒参考时间更改为2008年(例如JSR-310)

[英]Is it possible to change the base millisecond reference time from 1970 to 2008 in Java (like JSR-310)

I want to be able to change the base millisecond reference from 1970 to 2008 in Java so that I can save space in the database and unique Ids. 我希望能够将Java的基本毫秒引用从1970更改为2008,以便节省数据库和唯一ID的空间。

Preferably with Joda-Time. 最好与Joda-Time合作。

The upcoming jsr-310 in the supposed Java 7 release implements it. 假定的Java 7版本中即将发布的jsr-310实现了它。

In the The Discrete Timeline section of this link it states that the counting of milliseconds has changed from 1970 to 2008 在此链接的 “离散时间轴”部分中,它指出毫秒的计数从1970年更改为2008年

http://today.java.net/pub/a/today/2008/09/18/jsr-310-new-java-date-time-api.html http://today.java.net/pub/a/today/2008/09/18/jsr-310-new-java-date-time-api.html


The only other option I can see is to mathematically implement it every time I need to look up a record. 我可以看到的唯一其他选择是每次需要查找记录时都以数学方式实现它。

Eg 例如

DateTime dt = new DateTime();  
long now = dt.getMillis();

DateTime dt2 = new DateTime(2008, 1, 1, 0, 0, 0, 0);  
long then = dt2.getMillis();

long smallerDate = now - then;

Smaller date will be stored in the DB 较小的日期将存储在数据库中

-- Edit -- - 编辑 -

So I misread the JSR-310, and it's not possible. 因此我误读了JSR-310,这是不可能的。

There are better ways to save space and then a headache of processing thousands of request to calculate longs. 有更好的方法来节省空间,然后麻烦处理成千上万的请求以计算long。

I wanted to record longs as dates because I'll never know where I will move the DB to, perhaps MySQL => Oracle. 我想将longs记录为日期,因为我永远不知道将数据库移到哪里,也许MySQL => Oracle。

So I didn't want timestamps, I just wanted BigInts. 所以我不想要时间戳,我只想要BigInts。

No you can't, and it would be a bad idea if you could. 不,您不能,如果可以,那将是一个坏主意。 Every timestamp in your database is going to use the same space, regardless of how big the number is. 无论数字有多大,数据库中的每个时间戳都将使用相同的空间。 (Assuming you are storing the number as a number and not as a string or something.) (假设您将数字存储为数字而不是字符串或其他内容。)

Now, if you really want this, you'll have to write it yourself. 现在,如果您真的想要这个,则必须自己编写。 Ie subtract the time from your timestamps before putting them into the database, and add the time to the timestamps when you get them back out. 即,从时间戳中减去时间,然后再将其放入数据库中,并在将时间戳取回时将时间添加到时间戳中。 But this is asking for maintenance problems. 但这要求维护问题。 (In fact, using timestamps instead of the database's native DATETIME datatype is asking for problems.) (实际上,使用时间戳而不是数据库的本机DATETIME数据类型会引起问题。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM