需要在我获得的日期之后添加3天,但我需要避免星期六和太阳的日期....
我使用以下代码..
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat
//String dt = "2016-10-12"; // Start date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(dt));
c.add(Calendar.DATE, 3); // number of days to add
op = sdf.format(c.getTime()); // dt is now the new date
给定方案需要使用....应该添加3个工作日
Monday +3 days
Tuesday +3 days
Wednesday +5 days
Thursday +5 days
Friday +5 days
Saturday +4 days
Sunday +3 days
在javaScript中,我使用代码,但我需要在groovyScript中使用它...我是新手,我不知道该怎么做....我需要帮助..
var day = weekday[ invoiceDatee.getDay() ];
switch(day) {
case "Sunday":
invoiceDatee.setDate(invoiceDatee.getDate() + 3);
break;
case "Monday":
invoiceDatee.setDate(invoiceDatee.getDate() + 3);
break;
case "Tuesday":
invoiceDatee.setDate(invoiceDatee.getDate() + 3);
break;
case "Wednesday":
invoiceDatee.setDate(invoiceDatee.getDate() + 5);
break;
case "Thursday":
invoiceDatee.setDate(invoiceDatee.getDate() + 5);
break;
case "Friday":
invoiceDatee.setDate(invoiceDatee.getDate() + 5);
break;
case "Saturday":
invoiceDatee.setDate(invoiceDatee.getDate() + 4);
break;
default:
}
答案 0 :(得分:0)
试试这个,
def map = [1: 3, 2: 3, 3: 3, 4: 5, 5: 5, 6: 5, 7: 4]
c.add(Calendar.DATE, map[c.get(Calendar.DAY_OF_WEEK)]); // number of days to add