System.currentTimeMillis()何时溢出? [英] When will System.currentTimeMillis() overflow?
问题描述
我有一个网络应用程序,使用时间戳来订购内容,这只是一个很长的时间。我的网络应用程序后端碰巧是用java编写的,所以我正在使用:
long timestamp = System.currentTimeMillis();
哪一年(大约)会失败?我的意思是在某种程度上,长期的范围会溢出,对吧?我们都可能早已死,但我只是好奇。它会再次像y2k一样吗?我该怎么做才能做好准备?荒谬,我知道,只是好奇!
谢谢
它将溢出
System.out.println(新日期(Long.MAX_VALUE));
打印
Sun Aug 17 03:12:55 GMT-04:00 292278994
因此在经过了超过2.92亿年之后。我会说,同时发明解决方案的时间非常充足。说实话,我不指望人类能够幸存下来。与以小时为单位的
I have a web app which orders stuff using a timestamp, which is just a long. My web app backend happens to be written in java, so I am using:
long timestamp = System.currentTimeMillis();
what year (approximately) will this fail? I mean at some point, the range of a long is going to overflow, right? We may all be long-dead, but I'm just curious. Will it be like y2k all over again? What can I do to prepare for this? Ridiculous, I know, just curious!
Thanks
It will overflow at
System.out.println(new Date(Long.MAX_VALUE));
which prints
Sun Aug 17 03:12:55 GMT-04:00 292278994
That's thus after a bit more than 292 million years. I'd say, there's a plenty of time to invent a solution in the meanwhile. To be honest, I don't expect the humanhood to survive this. We exist only a few seconds as compared to the age of the world in hour scale and it won't take long.
这篇关于System.currentTimeMillis()何时溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!