Java Day of CountCmpHolidays(Date stdate, Date enddate, String[] CmpHoliDays)

Here you can find the source of CountCmpHolidays(Date stdate, Date enddate, String[] CmpHoliDays)

Description

Count Cmp Holidays

License

Open Source License

Declaration

public static int CountCmpHolidays(Date stdate, Date enddate, String[] CmpHoliDays) 

Method Source Code

//package com.java2s;
/*//w w  w  .j  ava 2s  .co  m
 * Copyright (C) 2012  Krawler Information Systems Pvt Ltd
 * All rights reserved.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static int CountCmpHolidays(Date stdate, Date enddate, String[] CmpHoliDays) {
        int NonWorkingDays = 0;
        Calendar c1 = Calendar.getInstance();
        DateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        try {
            c1.setTime(stdate);
            while ((stdate.compareTo(enddate)) < 0) {
                if (Arrays.binarySearch(CmpHoliDays, sdf1.format(c1.getTime())) >= 0) {
                    NonWorkingDays += 1;
                }
                c1.add(Calendar.DATE, 1);
                stdate = c1.getTime();
            }
        } catch (Exception e) {
            System.out.print(e.getMessage());
        }
        return NonWorkingDays;
    }
}

Related

  1. calcDay(String date1, String date2, String format)
  2. calcSunday(String queryDate)
  3. countDay(String begin, String end)
  4. endOfTheDay(Date date)
  5. formatDate(String day)
  6. formatDay(final Date time)