Java实现返回截止今日为止,当月工作日数

直接上代码,不多说。可以封装成公用类使用。

package com.edutohome.service;



import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.edutohome.dao.studentinfoDaoImpl;
import com.edutohome.vo.Attendance;

public class GetUnWeekendDays {

	//返回截止目前为止,当月工作日数
	public int getAttendance() throws Exception{
		int count = 0;
		int UnWeek;
		Date date = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String NowDate = df.format(date);
		
		String Days = NowDate.substring(8, 10);
		
		String item = Days.substring(0, 1);
		if(item.equals("0")){
			Days = Days.substring(1,2);
		}
		
		DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
		String strDate = NowDate.substring(0,10);
		//String strDate = "2016-10-10";	//test by Jiro.Chen
		
		String item1 = strDate.substring(0, 8);
		String item2 = strDate.substring(8,10);
		
		for(int i= 1; i <= Integer.parseInt(item2); i++){
			strDate = item1 + String.valueOf(i);
			
			Date dDate = format1.parse(strDate);
			Calendar cal = Calendar.getInstance();
			cal.setTime(dDate);
			if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
				//System.out.println("YES");
				count++;
			}else{
				//System.out.println("NO");
				continue;
			}
		}
		
		UnWeek = Integer.parseInt(item2) - count;
		
		return UnWeek;
	}
	
	
	public static void main(String args[]) throws Exception{
		SelectService sel = new SelectService();
		System.out.println(sel.getAttendance());
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值