Java Year Month getFirstDay(String yearMonthStr, int range)

Here you can find the source of getFirstDay(String yearMonthStr, int range)

Description

get First Day

License

Open Source License

Declaration

public static String getFirstDay(String yearMonthStr, int range) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

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

public class Main {

    public static String getFirstDay(String yearMonthStr, int range) {
        try {/*from w ww .j  a  v a  2s .c om*/
            DateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            Date date = sdf.parse(yearMonthStr + "01");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.MONTH, -(range - 1));
            Date first = calendar.getTime();
            return sdf.format(first);
        } catch (Exception e) {
        }
        return null;
    }
}

Related

  1. getCurYearMonth()
  2. getDate(int year, int month, int day)
  3. getDate(int year, int month, int day, int hour, int minute)
  4. getDaysOfMonth(String year, String month)
  5. getEndDateOfMonth(int year, int month)
  6. getFirstDayByMonthWeek(int year, int month, int week)
  7. getFirstDayOfMonth(int year, int month)
  8. getFirstDayOfMonth(int year, int month, Integer day)
  9. getFirstTimeOfDay(int year, int month, int day)