It is possible to calculate festivals such as Father's Day or Mother's Day, as well as to define a monthly best Friday to facilitate the scheduling of meetings.
/**
*
* @param strdate
* Start date, formatted as YYYY-MM-DD HH:MM:SS
* @param cyclepriod
* Repeat Interval
* @param looppriod
* Repeat type, m= month, d= Day, y= year, w= Week, H= hour, f= minute, s= second
* Mn= monthly positive number of days, mb= month countdown first days, such as MB2 for the 2nd day countdown
* W1. 7=, mn1w2= month, first week 2,mb2w4= month, Countdown 2nd Thursday
* W value can be multi-valued, w135 represents 1, Week 3, Friday
* @param Islunar
* Whether for the lunar calendar, the value must be the Gregorian calendar, the return of the lunar calendar is still the Gregorian calendar. The current lunar calendar is only a month and a year. Different repeat types are added as needed
* @return
*/
public static string Nexttime (string strdate, int cyclepriod,
String Looppriod, Boolean Islunar) {
String returnvalue = "";
int[] dates = dateutils.gendate (strdate);
Chinesecalendar Ccalendar = new Chinesecalendar ();
Ccalendar.setgregorianyear (Dates[0]);
Ccalendar.setgregorianmonth (Dates[1]);
Ccalendar.setgregoriandate (dates[2]);
if ("M". Equalsignorecase (Looppriod))//Processing month
{
if (Islunar) {
for (int i = 0; i < cyclepriod; i++) {
Ccalendar.nextchinesemonth ();
}
returnvalue = Dateutils.gendate (Ccalendar.getgregorianyear (),
Ccalendar.getgregorianmonth (),
Ccalendar.getgregoriandate ());
} else {
returnvalue = Dateutils.caldate (Strdate, Cyclepriod, 2);
}
else if ("D". Equalsignorecase (Looppriod))//Processing Day
{
returnvalue = Dateutils.caldate (Strdate, Cyclepriod, 5);
else if ("Y". Equalsignorecase (Looppriod))//Processing year
{
if (Islunar) {
Ccalendar.addchineseyear (Cyclepriod);
returnvalue = Dateutils.gendate (Ccalendar.getgregorianyear (),
Ccalendar.getgregorianmonth (),
Ccalendar.getgregoriandate ());
} else {
returnvalue = Dateutils.caldate (Strdate, Cyclepriod, 1);
}
else if ("W". Equalsignorecase (Looppriod))//Process Week
{
returnvalue = Dateutils.caldate (Strdate, Cyclepriod, 3);
else if ("H". Equalsignorecase (Looppriod))//Processing hours
{
returnvalue = Timeutils.addtime (strdate, 0, Cyclepriod);
else if ("F". Equalsignorecase (Looppriod))//processing minutes
{
returnvalue = Timeutils.addtime (strdate, 1, cyclepriod);
else if ("s". Equalsignorecase (Looppriod))//processing seconds
{
returnvalue = Timeutils.addtime (strdate, 2, cyclepriod);
} else//process non-regular period
{
if ("M". Equalsignorecase (Stringutils.left (Looppriod, 1)) {
String mnb = Looppriod.substring (1, 2);
String WNB = "";
int mnbvalue = 0;
int wnbvalue = 0;
if (Looppriod.indexof ("W") > 1) {
WNB = looppriod.substring (Looppriod.indexof ("w") + 1,
Looppriod.indexof ("W") + 2);
Mnbvalue = Integer.parseint (looppriod.substring (2,
Looppriod.indexof ("w"));
Wnbvalue = Integer.parseint (looppriod.substring (
Looppriod.indexof ("W") + 1, looppriod.length ()));
if ("N". Equalsignorecase (MNB)) {
ReturnValue = Getbeforeweekday (strdate, Mnbvalue,
Wnbvalue);
} else if ("B". Equalsignorecase (MNB)) {
ReturnValue = Getbackweekday (strdate, Mnbvalue,
Wnbvalue);
}
} else {
Mnbvalue = Integer.parseint (looppriod.substring (2,
Looppriod.length ())-1;
if ("N". Equalsignorecase (MNB)) {
returnvalue = Caldate (Givemonthfirst (strdate),
Mnbvalue, 5);
else if ("B". Equalsignorecase (MNB)) {
returnvalue = Caldate (Givemonthlast (strdate),
-mnbvalue, 5);
}
}
else if ("W". Equalsignorecase (Stringutils.left (Looppriod, 1)) {
String week = Stringutils.right (Looppriod,
Looppriod.length ()-1);
Strdate = Caldate (Strdate, cyclePriod-1, 3);
while (true) {
Strdate = Caldate (strdate, 1, 5);
if (Week.indexof (string.valueof (Getweekday (strdate)) >= 0) {
returnvalue = strdate;
Break
}
}
}
}
Return returnvalue;
}