Java Year Month getFirstDayByMonthWeek(int year, int month, int week)

Here you can find the source of getFirstDayByMonthWeek(int year, int month, int week)

Description

get First Day By Month Week

License

Open Source License

Declaration

public static String getFirstDayByMonthWeek(int year, int month, int week) 

Method Source Code

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

import java.text.DateFormat;

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

public class Main {
    public final static String YYYY_MM_DD = "yyyy-MM-dd";

    public static String getFirstDayByMonthWeek(int year, int month, int week) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd ");
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month - 1);
        c.set(Calendar.WEEK_OF_MONTH, week);

        int firstDayofweek = c.getFirstDayOfWeek();

        Calendar c1 = Calendar.getInstance();
        c1.set(Calendar.YEAR, year);
        c1.set(Calendar.MONTH, month - 1);
        c1.set(Calendar.WEEK_OF_MONTH, week);
        c1.set(Calendar.DAY_OF_WEEK, firstDayofweek);
        Date d1 = new Date(c1.getTimeInMillis());
        return df.format(d1);
    }/* www.  ja v a2s.  c om*/

    public static String format(Date date, String pattern) {
        if (date == null)
            return "";
        else
            return getFormatter(pattern).format(date);
    }

    public static String format(Date date) {
        if (date == null)
            return "";
        else
            return getFormatter(YYYY_MM_DD).format(date);
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. getDate(int year, int month, int day)
  2. getDate(int year, int month, int day, int hour, int minute)
  3. getDaysOfMonth(String year, String month)
  4. getEndDateOfMonth(int year, int month)
  5. getFirstDay(String yearMonthStr, int range)
  6. getFirstDayOfMonth(int year, int month)
  7. getFirstDayOfMonth(int year, int month, Integer day)
  8. getFirstTimeOfDay(int year, int month, int day)
  9. getFirstYearMonth()