码迷,mamicode.com
首页 > 编程语言 > 详细

获取十个工作日之前的日期 java

时间:2015-11-24 09:46:28      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/feiyuanxing/p/4990542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!