是否可以在Java中将基本毫秒参考时间从1970年更改为2008年(如JSR-310)
我希望能够在 Java 中更改从 1970 年到 2008 年的基本毫秒参考,所以 我可以节省数据库空间和唯一 ID。
最好与 Joda-Time 一起使用。
即将发布的 Java 7 版本中的 jsr-310 实现了它。
在此链接的“离散时间线”部分中,它指出毫秒计数从 1970 年到 2008 年已发生变化
http://today.java.net/pub/a/today/2008/09/18/jsr-310-new-java-date-time-api.html
唯一我能看到的另一个选择是每次都以数学方式实现它 我需要查一下记录。
例如,
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;
较小的日期将存储在数据库中
- 编辑 -
所以我误读了 JSR-310,这是不可能的。
有更好的方法来节省空间然后头痛 处理数千个请求来计算长整型。
我想将 long 记录为日期,因为我永远不知道我会搬到哪里 DB 到,也许 MySQL =>甲骨文。
所以我不需要时间戳,我只想要 BigInts。
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.
Preferably with Joda-Time.
The upcoming jsr-310 in the supposed Java 7 release implements it.
In the The Discrete Timeline section of this link it states that the counting of milliseconds has changed from 1970 to 2008
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.
E.g.
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.
There are better ways to save space and then a headache of
processing thousands of request to calculate longs.
I wanted to record longs as dates because I'll never know where I will move
the DB to, perhaps MySQL => Oracle.
So I didn't want timestamps, I just wanted BigInts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你不能,如果你能的话那就是个坏主意。数据库中的每个时间戳都将使用相同的空间,无论数字有多大。 (假设您将数字存储为数字而不是字符串或其他内容。)
现在,如果您确实想要这个,则必须自己编写它。即,在将它们放入数据库之前从时间戳中减去时间,并在将它们取出时将时间添加到时间戳中。但这会带来维护问题。 (事实上,使用时间戳而不是数据库的本机 DATETIME 数据类型会带来问题。)
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. I.e. 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.)