//判断两天是不是同一天 public static boolean isSameDate(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); boolean isSameYear = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR); boolean isSameMonth = isSameYear && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH); boolean isSameDate = isSameMonth && cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH); return isSameDate; } //得到距离今天是i天的天数 1代表明天 2代表后天 public static Date getDay(int i) { Date date = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_MONTH, i); date = calendar.getTime(); return date; } //判断某现在时刻是否在某一时段内 public static boolean isInDate(Date sDate, Date eDate) { Date now = new Date(); boolean b = now.after(sDate) && now.before(eDate); return b; }
时间工具类
最新推荐文章于 2022-10-25 21:43:11 发布