Java Month of Year getThisMonth(int year, int monthIndex)

Here you can find the source of getThisMonth(int year, int monthIndex)

Description

get This Month

License

Open Source License

Declaration

public static Calendar getThisMonth(int year, int monthIndex) 

Method Source Code

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

import java.util.Calendar;

public class Main {
    public static Calendar getThisMonth(int year, int monthIndex) {
        Calendar thisMonth = Calendar.getInstance();
        if (year > 1900)
            thisMonth.set(Calendar.YEAR, year);
        else/*from  ww w. j a  v a  2  s.  com*/
            thisMonth.set(Calendar.YEAR, 1901);

        if (monthIndex >= 0 && monthIndex < 12)
            thisMonth.set(Calendar.MONTH, monthIndex);
        else
            thisMonth.set(Calendar.MONTH, 0);

        thisMonth.setFirstDayOfWeek(Calendar.SUNDAY);

        thisMonth.set(Calendar.DAY_OF_MONTH, 1);
        return thisMonth;
    }
}

Related

  1. getPrevMonth(String divisionDate, int day, String outputFormat)
  2. getPreYearMonth()
  3. getSecondsOfMonth(int year, int month)
  4. getStartAndEndOfMonth(int month, int year)
  5. getStrDayOfWeek(int _year, int _month, int _day)
  6. getTime(int year, int month, int day)
  7. getTimeByYMD(int year, int month, int day)
  8. getTimestamp(int year, int month, int day, int hour, int minute, int second, int millisecond)
  9. getTodayAdd(int year, int month, int day)