java计算工作日方法

来源:互联网 发布:温州领导干部网络学堂 编辑:程序博客网 时间:2024/05/16 06:04
java计算工作日,实测有效
public static Date getDate(Date currentDate, int days){    Calendar calendar= Calendar.getInstance();    calendar.setTime(currentDate);    int i=0;    while(i<days){        calendar.add(Calendar.DATE,-1);//整数往后推日期,负数往前推日期        i++;        if(calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY ||                calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){            i--;        }    }    SimpleDateFormat dateformat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    System.out.println(dateformat.format(calendar.getTime()));    return calendar.getTime();}
原创粉丝点击