【原创】java 获取十个工作日之后的日期(算当天)-完美解决-费元星(仅考虑星期六星期天)
/**
*
* 根据开始日期 ,需要的工作日天数 ,计算工作截止日期,并返回截止日期
* @param startDate 开始日期
* @param workDay 工作日天数(周一到周五)
* @author 【狒狒:Q97175234】
* @time 2015-11-23 上午9:21:25
*
* @motto 既然笨到家,就要努力到家...
*
*/
public static Date getWorkDay(Date startDate, int workDay) {
Calendar c1 = Calendar.getInstance();
c1.setTime(startDate);
for (int i = 0; i < workDay; i++) {
c1.set(Calendar.DATE, c1.get(Calendar.DATE) + 1);
if (Calendar.SATURDAY == c1.get(Calendar.SATURDAY) || Calendar.SUNDAY == c1.get(Calendar.SUNDAY)) {
workDay = workDay + 1;
c1.set(Calendar.DATE, c1.get(Calendar.DATE) + 1);
continue;
}
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(c1.getTime()) + " " + getWeekOfDate(c1.getTime()));
return c1.getTime();
}
/**
* 根据日期,获取星期几
* @param dt
* @return String类型
* @author 【狒狒:Q9715234】
* @time 2015-11-23 上午9:21:25
* @motto 既然笨到家,就要努力到家...
*/
public static String getWeekOfDate(Date dt) {
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0) w = 0;
return weekDays[w];
}
【原创】java 获取十个工作日之前的日期(算当天)-完美解决-费元星(仅考虑星期六星期天)
/**
*
* 根据开始日期 ,需要的工作日天数 ,计算工作截止日期,并返回截止日期
* @param startDate 开始日期
* @param workDay 工作日天数(周一到周五)
* @author 【狒狒:Q9715234】
* @time 2015-11-23 上午9:21:25
*
* @motto 既然笨到家,就要努力到家...
*
*/
public static String getWorkDay(Date startDate, int workDay) {
Calendar c1 = Calendar.getInstance();
c1.setTime(startDate);
for (int i = 0; i < workDay; i++) {
c1.set(Calendar.DATE, c1.get(Calendar.DATE) -1);
if (Calendar.SATURDAY == c1.get(Calendar.SATURDAY) || Calendar.SUNDAY == c1.get(Calendar.SUNDAY)) {
workDay = workDay + 1;
c1.set(Calendar.DATE, c1.get(Calendar.DATE) - 1);
continue;
}
}
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
c1.set(Calendar.DATE, c1.get(Calendar.DATE) +1);
// System.out.println(df.format(c1.getTime()) + " " + getWeekOfDate(c1.getTime()));
return df.format(c1.getTime());
}
/**
* 根据日期,获取星期几
* @param dt
* @return String类型
* @author 【狒狒:Q9715234】
* @time 2015-11-23 上午9:21:25
* @motto 既然笨到家,就要努力到家...
*/
public static String getWeekOfDate(Date dt) {
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0) w = 0;
return weekDays[w];
}
public static void main(String[] args) {
// Date date = AppUtil.getCurrentDate2();
System.out.println("工作日: 8天之前 " +getWorkDay(new Date(), 8));
System.out.println("工作日: 9天之前 " +getWorkDay(new Date(), 9));
System.out.println("工作日: 10天之前 " +getWorkDay(new Date(), 10));
System.out.println("工作日: 11天之前 " +getWorkDay(new Date(), 11));
}