Here you can find the source of getStartOfMonth(Date day, Calendar cal)
public static Date getStartOfMonth(Date day, Calendar cal)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { /**//from w w w . j a v a 2 s. c o m * Returns a Date set to the first possible millisecond of the month, just * after midnight. If a null day is passed in, a new Date is created. * midnight (00m 00h 00s) */ public static Date getStartOfMonth(Date day) { return getStartOfMonth(day, Calendar.getInstance()); } public static Date getStartOfMonth(Date day, Calendar cal) { if (day == null) day = new Date(); cal.setTime(day); // set time to start of day cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND)); // set time to first day of month cal.set(Calendar.DAY_OF_MONTH, 1); return cal.getTime(); } }