Java Month Day getFirstDateOfMonth(Date theDate)

Here you can find the source of getFirstDateOfMonth(Date theDate)

Description

get First Date Of Month

License

Open Source License

Declaration

public static Date getFirstDateOfMonth(Date theDate) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    private static final int[] DAY_OF_MONTH = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

    public static Date getFirstDateOfMonth(Date theDate) {
        Calendar c = new GregorianCalendar();
        c.setTime(theDate);//from ww  w .j  a  v  a 2  s .c o  m
        c.set(Calendar.DAY_OF_MONTH, 1);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }

    public static String getTime(Date dt, String format) {
        SimpleDateFormat st = new SimpleDateFormat(format);
        return st.format(dt);
    }
}

Related

  1. getDaysInMonth(final Date date)
  2. getDaysOfMonth(Date date)
  3. getDaysOfMonth(Date date)
  4. getFirstDate(String base_month)
  5. getFirstDateOfCurMonth()
  6. getFirstday_Month(Date date, int months)
  7. getFirstDayOfCurMonth()
  8. getFirstDayOfCurrentMonth()
  9. getFirstDayOfLastMonth()