For example, the Dragon Boat Festival has an operating activities, only from June 7 to June 11, expired automatically off the line. The following code can implement this functionality.
static{
String s1= "2016-06-07 00:00:00";
String s2= "2016-06-12 00:00:00";
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
try {
start=sdf.parse (S1);
End=sdf.parse (s2);
} catch (ParseException e) {
e.printstacktrace ();
}
}
/**
* To determine whether the current time in the Dragon Boat Festival activity interval
* *
private Boolean isduanwuperiod () {
date date=new date ();
if (end!=null && start!=null && date.before (end) && date.after (start)) {return
true;
} return
false;
}
The reason to put the start and end time of the build inside the static initialization block is to avoid repetition.
You can then add the Isduanwuperiod method before the feature business function code.
PS: In the actual project can be configured to configure the file time, so more flexible ~