Here you can find the source of getFirstDayOfMonth(int year, int month, Integer day)
public static String getFirstDayOfMonth(int year, int month, Integer day)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static String getFirstDayOfMonth(int year, int month, Integer day) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); if (day == null) { cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE)); } else {//from w ww . ja v a 2s. c o m cal.set(Calendar.DAY_OF_MONTH, day); } StringBuffer sb = new StringBuffer(); String date = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); sb.append(date).append(" 00:00"); return sb.toString(); } }