Here you can find the source of getFirstDayOfMonth(Date date)
Parameter | Description |
---|---|
date | a parameter |
public static Date getFirstDayOfMonth(Date date)
//package com.java2s; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static final String format0 = "yyyy-MM-dd HH:mm:ss"; public static final String format2 = "yyyy-MM"; public static Date getFirstDayOfMonth(Date date) { if (null == date) return null; return parserDate(getFirstDayStringOfMonth(date), format2); }/*from w w w.j av a 2 s .com*/ public static Date parserDate(String str, String format) { if (null == str || "".equals(str) || "NULL".equalsIgnoreCase(str)) return null; if (null == format) format = format0; java.util.Date d = Calendar.getInstance().getTime(); if (str.length() == 10) str = str + " 00:00:00"; SimpleDateFormat formatter = new SimpleDateFormat(format); ParsePosition pos = new ParsePosition(0); d = formatter.parse(str, pos); return d; } public static Date parserDate(String str) { if (null == str) return null; return parserDate(str, format0); } public static String getFirstDayStringOfMonth(Date date) { if (null == date) return null; return getFormateDateString(date, format2); } public static String getFormateDateString(Date date, String format) { if (date == null) return null; SimpleDateFormat dateFormat = new SimpleDateFormat(format); return dateFormat.format(date); } }