明明是天卻顯示年,用電腦的計算器計算是對的,剛開始沒注意,仔細一看,代碼段背景是淡黃色的,鼠標懸浮提示:Numeric overflow
https://blog.csdn.net/qq_30290513/article/details/77948008
整數後面加 L 就行了。
long ms = date1.getTime() - date.getTime();
if (Math.floor((double)ms/(1000L*60L*60L*24L*365L)) >= 1) {
title += ms/(1000L*60L*60L*24L*365L) + "年";
} else if (Math.floor((double)ms/(1000L*60L*60L*24L*30L)) >= 1) {
title += ms/(1000L*60L*60L*24L*30L) + "月";
} else if (Math.floor((double)ms/(1000*60*60*24)) >= 1) {
title += ms/(1000*60*60*24) + "天";
}