寫了一個簡單的計算父親節母親節等日期的方法

項目中要查父親節,母親節的節日,隨手寫了一個小方法,記錄一下。java

 

//能夠用來計算父親節 母親節 感恩節等
//計算好比父親節母親節感恩節這種某個月的第幾個周幾的狀況
private static String getCaculateDate(int n ,String rawWeek,String festWeek ) {
int a = 0;
String sDays = null;
if (rawWeek.equals("Mon")) {
a = 1;
}else if (rawWeek.equals("Tue")){
a = 2;
}else if (rawWeek.equals("Wed")){
a = 3;
}else if (rawWeek.equals("Thu")){
a = 4;
}else if (rawWeek.equals("Fri")){
a = 5;
}else if (rawWeek.equals("Sat")){
a = 6;
}else if (rawWeek.equals("Sun")){
a = 7;
}
int b = 0;
if (festWeek.equals("Mon")) {
b = 1;
}else if (festWeek.equals("Tue")){
b = 2;
}else if (festWeek.equals("Wed")){
b = 3;
}else if (festWeek.equals("Thu")){
b = 4;
}else if (festWeek.equals("Fri")){
b = 5;
}else if (festWeek.equals("Sat")){
b = 6;
}else if (festWeek.equals("Sun")){
b = 7;
}
int days = 0;
if (a == b) {
days = 7*(n-1)+b+(7-a+1);
}else if (a < b) {
days = 7*(n-1)-(7-b)+(b-a+1);
}else if (a > b) {
days = 7*(n-1)+b+(7-a+1);
}
if (days<10) {
sDays = "0"+days;
}else {
sDays = String.valueOf(days);
}
return sDays;
}
相關文章
相關標籤/搜索