public static TimeInfo getLastMonthStartAndEndTime() { Calendar calendar1 = Calendar.getInstance(); calendar1.add(Calendar.MONTH, -1); calendar1.set(Calendar.DATE, 1); calendar1.set(Calendar.HOUR_OF_DAY, 0); calendar1.set(Calendar.MINUTE, 0); calendar1.set(Calendar.SECOND, 0); calendar1.set(Calendar.MILLISECOND, 0); Date startDate = calendar1.getTime(); long startTime = startDate.getTime(); Calendar calendar2 = Calendar.getInstance(); calendar2.add(Calendar.MONTH, -1); calendar2.set(Calendar.DATE, 1); calendar2.set(Calendar.HOUR_OF_DAY, 23); calendar2.set(Calendar.MINUTE, 59); calendar2.set(Calendar.SECOND, 59); calendar2.set(Calendar.MILLISECOND, 999); calendar2.roll(Calendar.DATE, -1); Date endDate = calendar2.getTime(); long endTime = endDate.getTime(); TimeInfo info = new TimeInfo(); info.setStartTime(startTime); info.setEndTime(endTime); return info; }
private static boolean isSameDay(long inputTime) { TimeInfo tStartAndEndTime = getTodayStartAndEndTime(); if (inputTime > tStartAndEndTime.getStartTime() && inputTime < tStartAndEndTime.getEndTime()) return true; return false; }
public static TimeInfo getTodayStartAndEndTime() { Calendar calendar1 = Calendar.getInstance(); calendar1.set(Calendar.HOUR_OF_DAY, 0); calendar1.set(Calendar.MINUTE, 0); calendar1.set(Calendar.SECOND, 0); calendar1.set(Calendar.MILLISECOND, 0); Date startDate = calendar1.getTime(); long startTime = startDate.getTime(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss S"); Calendar calendar2 = Calendar.getInstance(); calendar2.set(Calendar.HOUR_OF_DAY, 23); calendar2.set(Calendar.MINUTE, 59); calendar2.set(Calendar.SECOND, 59); calendar2.set(Calendar.MILLISECOND, 999); Date endDate = calendar2.getTime(); long endTime = endDate.getTime(); TimeInfo info = new TimeInfo(); info.setStartTime(startTime); info.setEndTime(endTime); return info; }
private static boolean isYesterday(long inputTime) { TimeInfo yStartAndEndTime = getYesterdayStartAndEndTime(); if (inputTime > yStartAndEndTime.getStartTime() && inputTime < yStartAndEndTime.getEndTime()) return true; return false; }