Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Java date calculation problem
Java date calculation problem
The link of Tonylian77 is really a good article, but the landlord should mean to modify the time in this method, and I feel that the landlord wrote the name of the method wrong when asking questions. The publishing method should be setDate, right? Tech_java people pointed out the problem. In java, int is 32 bits, and its maximum value is 2 147483647 (this maximum value can be obtained through Integer. MAX_VALUE)。 When day=24, the result of the formula is 2073600000 * 60 * 24 * day. When day=25, the result is 2 160000000, which is bound to overflow;

In addition, although the definition of L as a long type is 32 bits, the result will be an int type because the operands on the right side of the equation are all int types, and then the negative value obtained after overflow will be forcibly converted into a long type and added with L, so the result is wrong; But brother tech_java said to change it to 1000.0 * 60 * 60 * 24 * days. I don't agree with this, because it will be converted to floating-point type and changed to 1000L * 60 * 24 * day. I believe this may be just a clerical error of brother tech_java, hehe ~

So I don't know if the landlord understands ~