public static int daysBetween(String smdate, String bdate, String levelID) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(sdf.parse(smdate));
long time1 = cal.getTimeInMillis();
cal.setTime(sdf.parse(bdate));
long time2 = cal.getTimeInMillis();
int day = 0;
long minutes = (time2 - time1) / (1000 * 60);//2者的分钟数值
day = (int) (minutes / 1440); //求天
int min = (int) (minutes % 1440); //求分钟
if (levelID.equals("1")) {
if (min > 60) {
day += 1;
}
}
if (levelID.equals("2")) {
if (min > 120) {
day += 1;
}
}
if (levelID.equals("3")) {
if (min > 180) {
day += 1;
}
}
return day;
}
android计算2个时间差N分钟
最新推荐文章于 2024-08-04 03:33:53 发布