When will the java date collapse?

后端 未结 2 1162
终归单人心
终归单人心 2020-12-11 15:08

AFAIK java stores dates in long variables as milliseconds. Consequently someday there will be no value (cause long has a maximum) which will correspond to the time of that i

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 15:34

    It's easy enough to find out:

    public class Test {
        public static void main(String[] args) {
            System.out.println(new java.util.Date(Long.MAX_VALUE));
        }
    }
    

    Gives output (on my box):

    Sun Aug 17 07:12:55 GMT 292278994
    

    You may need to subtract a bit from Long.MAX_VALUE to cope with your time zone overflowing the range of long, but it will give a reasonable ballpark :)

提交回复
热议问题