Here you can find the source of getFirstDay(String yearMonthStr, int range)
public static String getFirstDay(String yearMonthStr, int range)
//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; } }