Java Day of Month getFirstDayOfMonth(Date date)

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

Description

get First Day Of Month

License

Apache License

Declaration

public static Date getFirstDayOfMonth(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static Date getFirstDayOfMonth(int year, int month) {
        Calendar calender = Calendar.getInstance();
        calender.set(year, month - 1, 1);
        calender.set(Calendar.DAY_OF_MONTH, calender.getActualMinimum(Calendar.DAY_OF_MONTH));
        setStartTimeOfDay(calender);//from w w  w.j  av  a  2 s.co m
        return calender.getTime();
    }

    public static Date getFirstDayOfMonth(Date date) {
        Calendar calender = Calendar.getInstance();
        calender.setTime(date);
        calender.set(Calendar.DAY_OF_MONTH, calender.getActualMinimum(Calendar.DAY_OF_MONTH));
        setStartTimeOfDay(calender);
        return calender.getTime();
    }

    private static void setStartTimeOfDay(Calendar calender) {
        calender.set(Calendar.HOUR_OF_DAY, calender.getActualMinimum(Calendar.HOUR_OF_DAY));
        calender.set(Calendar.MINUTE, calender.getActualMinimum(Calendar.MINUTE));
        calender.set(Calendar.SECOND, calender.getActualMinimum(Calendar.SECOND));
        calender.set(Calendar.MILLISECOND, calender.getActualMinimum(Calendar.MILLISECOND));
    }
}

Related

  1. getDayOfMonth(Date date)
  2. getDayOfMonth(Date date)
  3. getDayOfMonth(Date date)
  4. getDayOfMonth(Date dt)
  5. getDayOfMonth(final Date date)
  6. getFirstDayOfMonth(Date date)
  7. getFirstDayOfMonth(java.util.Date date)
  8. getFirstMiddleDayOfMonth(Date date)
  9. getFistDayOfMonth(Date date)