1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| package com.date.utils;
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date;
public class judgeDate {
public static boolean isEffectiveDate() throws ParseException {
Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String today = df.format(date);
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date startTime = ft.parse(today + " 00:00"); Date endTime = ft.parse(today + " 08:00");
Date nowTime = new Date();
boolean effectiveDate = isEffectiveDate2(nowTime, startTime, endTime);
return effectiveDate; }
public static boolean isEffectiveDate2(Date nowTime, Date startTime, Date endTime) { if (nowTime.getTime() == startTime.getTime() || nowTime.getTime() == endTime.getTime()) { return true; }
Calendar date = Calendar.getInstance(); date.setTime(nowTime);
Calendar begin = Calendar.getInstance(); begin.setTime(startTime);
Calendar end = Calendar.getInstance(); end.setTime(endTime);
if (date.after(begin) && date.before(end)) { return true; } else { return false; } }
}
|