Java时间差计算返回时差
? ? ? ?public static void main(String[] args) {
BigDecimal startT= new BigDecimal(fromDateStringToLong("2011-05-05 19:30:10"));
BigDecimal endT =new BigDecimal(fromDateStringToLong("2011-05-05 16:30:20"));
BigDecimal mm = new BigDecimal((startT.doubleValue() - endT.doubleValue())/3600000);
System.out.println(mm.setScale(1,BigDecimal.ROUND_HALF_UP));
}
?
?
public static long fromDateStringToLong(String inVal) {?
Date date = null; ?
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
date = sdf.parse(inVal);?
} catch (Exception e) {
e.printStackTrace();
}
return date.getTime();?
}