计算时间差。
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat
/**
* @Description 获取相差多少年,当前系统时间减去起始跑车时间
*
* @param fstTm 起始跑车时间
*
* @return
*
* @throws Exception
*/
private double getYear(String fstTm) throws Exception {
//当前日期时间
Date d1=new Date();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
String str1 = df.format(d1);
//变量日期时间
Date d2 = df.parse(fstTm);
long timeNow=d1.getTime();
long timeOld=d2.getTime();
long day=(timeNow-timeOld)/(1000*60*60*24);//化为天
float dayYear = 365;
BigDecimal bg = new BigDecimal(day / dayYear);
double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
return f1;
}