Java Month Day GetLastWorkDayofMonth(String strDateStart)

Here you can find the source of GetLastWorkDayofMonth(String strDateStart)

Description

Get Last Work Dayof Month

License

Open Source License

Declaration

public static Date GetLastWorkDayofMonth(String strDateStart)
        throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {

    public static Date GetLastWorkDayofMonth(String strDateStart)
            throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date date_start = sdf.parse(strDateStart);
        Calendar cal_start = Calendar.getInstance();
        cal_start.setTime(date_start);//from   w w  w  . ja va  2s .co  m

        int dayOfWeek = cal_start.get(Calendar.DAY_OF_WEEK) - 1;
        Date a = new Date();
        if (dayOfWeek == 1) {
            a = AddDate(date_start, -3);
        } else if (dayOfWeek == 7) {
            a = AddDate(date_start, -2);
        } else {
            a = AddDate(date_start, -1);
        }
        // System.out.println(GetFormattedDateUtil(a, "yyyy-MM-dd"));
        return a;
    }

    /**
     * 
     * @param date
     *            Date
     * @param days
     *            int
     * @return Date
     */
    public static Date AddDate(Date date, int days) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        long lTmp = c.getTimeInMillis();
        c.setTimeInMillis(lTmp + ((long) days) * 24 * 3600 * 1000);
        return c.getTime();
    }
}

Related

  1. getLastMonthDay()
  2. getLastMonthLastDate()
  3. getLastMonthLastDay()
  4. getLastMonthLastDay()
  5. getLastMothStart()
  6. getMonthDay(int year, int month)
  7. getMonthEndDay(String time)
  8. getMonthEndDay(String yyyy, String mm)
  9. getMonthFirstDay()