1000 * 60 * 60 * 24 * 30 results in a negative number
1000 * 60 * 60 * 24 * 30 results in a negativeĀ number
You are multiplyingĀ intsĀ together, and overflow occurs becauseĀ the maximum integer isĀ 2^31 - 1. Only after the multiplications does it get converted to aĀ long. Cast the first number as aĀ long. long days_30 = (long) 1000 * 60 * 60 * 24 * 30; or use aĀ longĀ literal: long days_30 = 1000L * 60 * 60 * 24 * 30; That will forceĀ longĀ math operations from the start.
View On WordPress

















