Here you can find the source of getFirstDayOfMonth(Date date)
public static String getFirstDayOfMonth(Date date)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map; public class Main { private static final String dateFormat3 = "yyyy-MM-dd"; private static final Map<String, DateFormat> DFS = new HashMap<String, DateFormat>(); public static String getFirstDayOfMonth(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);/*from w ww . j av a 2s . co m*/ cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE)); return date2String(cal.getTime()); } public static String date2String(Date date) { SimpleDateFormat formatter = new SimpleDateFormat(dateFormat3); String dateString = formatter.format(date); return dateString; } public static String format(Date date, String pattern) { if (date == null) { return null; } return getFormat(pattern).format(date); } public static DateFormat getFormat(String pattern) { DateFormat format = DFS.get(pattern); if (format == null) { format = new SimpleDateFormat(pattern); DFS.put(pattern, format); } return format; } }