TimeUtils { public static Date beginMonth(int year, int month) { if (month < 0 || month > 11) return null; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return new Date(calendar.getTime().getTime()); } private  TimeUtils(); static String nowStr(); static String date2Str(Date date); static String date2Str(long date); static int month(); static Date yesterdayBegin(); static Date yesterdayEnd(); static Date pastWeekStart(); static Long howLongBeginThisMonth(); static Date beginThisMonth(); static Date lastMonthTodayInBegin(); static Date lastFewDaysInBegin(Integer days); static Date fewDaysAgoEnd(int index); static Date fewDaysAgoBegin(int index); static Date endMonth(int year, int month); static Date beginMonth(int year, int month); static Date zeroTimeZone(Date date); static String nowTimeWithZone();  }
@Test public void beginMonthTester() { assertEquals("2016-07-01 00:00:00:000", sdf.format(TimeUtils.beginMonth(2016, 7))); }