Here you can find the source of getMonthFirstDay(T date)
public static <T extends Date> T getMonthFirstDay(T date)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static <T extends Date> T getMonthFirstDay(T date) { if (date == null) return null; String dateStr = format(date, "yyyy-MM") + "-01"; Long mill = parseDate(dateStr).getTime(); T another = (T) date.clone();//w ww . jav a 2 s .c o m another.setTime(mill); return another; } /** * @param date * @param pattern: Date format pattern * @return */ public static final <T extends Date> String format(T date, String pattern) { if (date == null) return null; try { SimpleDateFormat df = new SimpleDateFormat(pattern); String result = df.format(date); return result; } catch (Exception e) { return null; } } public static final Date parseDate(String strDate) { Date date = null; try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); date = dateFormat.parse(strDate); return date; } catch (Exception pe) { return null; } } /** * @param strDate * @param pattern * @return */ public static final Date parseDate(String strDate, String pattern) { SimpleDateFormat df = null; Date date = null; df = new SimpleDateFormat(pattern); try { date = df.parse(strDate); return date; } catch (Exception pe) { return null; } } }