SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date startDate = null;
Date endDate = null;
try {
startDate=inputFormat.parse("2017-09-01 20:00:00");
endDate=inputFormat.parse("2017-09-02 20:00:00");
} catch (ParseException e) {
e.printStackTrace();
}
//得到两个日期对象的总毫秒数
long firstDateMilliSeconds = startDate.getTime();
long secondDateMilliSeconds = endDate.getTime();
//得到两者之差
long firstMinusSecond = secondDateMilliSeconds - firstDateMilliSeconds;
//得到秒
long totalSeconds = (firstMinusSecond / 1000);
两个字符串时间算时间差
最新推荐文章于 2023-07-14 13:52:59 发布