문제

I've got a bunch of Dates and I want to find their average.

  • How many Dates within 100 years of now can I sum before I run into overflow problems? Any gotchas?
  • What's the best way to calculate the average, avoiding overflow problems?
도움이 되었습니까?

해결책

System.out.println(Long.MAX_VALUE / System.currentTimeMillis());

Output:

6892653

I think this answers both of your questions. You can also divide each epoch value by 1000*60*60*24, but given the size of that raw quotient, even that's probably overkill.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top