DateUtil { public static Date getYrMonthFirstDay(final Date d) { String yrMonth = DateUtil.date2String(d, "yyyyMM"); String date = yrMonth + "01"; return DateUtil.string2Date(date); }  static Date string2Date(final String ds); static Date string2Date(final String date, final String format); static String date2String(final Date date); static String date2String(final Date date, final String format); static String getCurrentTimestamp(); static long getCurrentTime(); static Date getCurrentDate(); static int daysBetween(final Date startDate); static Date getYrMonthLastDay(final Date d); static Date getYrMonthFirstDay(final Date d); static int daysBetween(final Date startDate, final Date endDate);  }
@Test public void getYrMonthFirstDay() { Date t1 = DateUtil.string2Date("2018-02-20"); Date t2 = DateUtil.getYrMonthFirstDay(t1); String str = DateUtil.date2String(t2, DateConstants.DATE_FORMAT_10); Assert.equals(str, "2018-02-01", ErrorCodeDef.SYSTEM_ERROR_10001); }