Here you can find the source of getfirstDayOfMonth()
public static Date getfirstDayOfMonth()
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static final int MINUTE = 2; public static final String YYYYMMDD = "yyyy-MM-dd"; public static Date getfirstDayOfMonth() { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat(YYYYMMDD); // String sdate = format.format(date); Calendar sCal = Calendar.getInstance(); sCal.setTime(date);//from w w w. jav a2 s . c om sCal.add(Calendar.DAY_OF_MONTH, -(sCal.get(Calendar.DAY_OF_MONTH) - 1)); try { date = format.parse(format.format(sCal.getTime())); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date; } public static Date add(Date date, long minutes) { if (date == null) { throw new IllegalArgumentException(); } return addMinutes(date, minutes); } public static java.util.Date addMinutes(java.util.Date date, long... minutes) { if (minutes == null) { return date; } java.util.Calendar c = java.util.Calendar.getInstance(); c.setTime(date); for (long minute : minutes) { c.add(Calendar.MINUTE, (int) minute); } return c.getTime(); } public static Date addMinutes(Date date, long minutes) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(getMillis(date) + ((long) minutes) * 60 * 1000); return c.getTime(); } public static long getMillis(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); return c.getTimeInMillis(); } }