Java Month Day getFirstDayOfMonth(Date date)

Here you can find the source of getFirstDayOfMonth(Date date)

Description

get First Day Of Month

License

Open Source License

Declaration

public static Date getFirstDayOfMonth(Date date) throws ParseException 

Method Source Code


//package com.java2s;
import java.text.ParseException;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getFirstDayOfMonth(Date date) throws ParseException {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);/*from  w w w.  ja v  a 2 s . c om*/
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);
        return calendar.getTime();
    }

    public static Date getFirstDayOfMonth(Integer year, Integer month) {
        Calendar calendar = Calendar.getInstance();
        if (year == null) {
            year = calendar.get(Calendar.YEAR);
        }
        if (month == null) {
            month = calendar.get(Calendar.MONTH);
        }
        calendar.set(year, month, 1);
        return calendar.getTime();
    }
}

Related

  1. getFirstDayOfLastMonth()
  2. getfirstDayOfMonth()
  3. getFirstDayOfMonth(Calendar c)
  4. getFirstDayOfMonth(Date date)
  5. getFirstDayOfMonth(Date date)
  6. getFirstDayOfMonth(Date date)
  7. getFirstDayOfMonth(Date date)
  8. getFirstDayOfMonth(Long date)
  9. getFirstDayOfNextMonth()