Let's first make an example: the current time is 10:27:01. 89
// 24*60*60*1000 indicates the number of milliseconds in a day. The value of 24 indicates 24 days. <br/> long daylong = 24*24*60*60*1000; <br/> // system. currenttimemillis ()-daylong indicates the current time minus the 24-day time <br/> timestamp T = new timestamp (system. currenttimemillis ()-daylong); <br/> // print time <br/> system. out. println (t );
Program output: 10:27:01. 89
When the first 24 in daylong is changed to 25, guess what the output is? 2011-04-23 10:27:01. 89
?
The program output is 03:27:01. 89.
Why?
This is because 25*24*60*60*1000 is out of the integer int range. in Java, the int value range is-2 ^ 31 ~ 2 ^ 31-1
That is,-2147483648 ~2147483647
In the int value range, 24*24*60*60*1000 = 2073600000
While 25*24*60*60*1000 =-2134967296
!
Solution: force type conversion to long type, long daylong = (long) 25*24*60*60*1000
; Daylong = 2160000000
Program output: 10:27:01. 89