Here you can find the source of getFirstDay(Date date)
static public Date getFirstDay(Date date)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**/*from www.j av a 2 s .c o m*/ * format pattern : yyyy-MM-dd */ public static final SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd"); /** * Get first day of the month. * * @param year * the year * @param month * the month * @return Date first day of the month. * @throws ParseException */ static public Date getFirstDay(String year, String month) throws ParseException { return FORMAT_YYYY_MM_DD.parse(year + "-" + month + "-1"); } static public Date getFirstDay(int year, int month) throws ParseException { return FORMAT_YYYY_MM_DD.parse(year + "-" + month + "-1"); } static public Date getFirstDay(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.DAY_OF_MONTH, 1); return c.getTime(); } }