Java Day of Month getFistDayOfMonth(Date date)

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

Description

get Fist Day Of Month

License

Apache License

Declaration

public static Integer getFistDayOfMonth(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 Integer getFistDayOfMonth(Date date) {
        Integer intDate = getIntDate(date);
        int year = intDate / 10000;
        int month = intDate % 10000 / 100;
        return getIntDate(newCalendar(year, month, 1));
    }//from w  w  w.j a  v  a  2 s  .com

    public static Integer getIntDate(int year, int month, int day) {
        return getIntDate(newCalendar(year, month, day));
    }

    public static Integer getIntDate(Calendar c) {
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int day = c.get(Calendar.DAY_OF_MONTH);
        return year * 10000 + month * 100 + day;
    }

    public static Integer getIntDate(Date d) {
        if (d == null) {
            return null;
        }
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        return getIntDate(c);
    }

    public static Calendar newCalendar(int year, int month, int day) {
        Calendar ret = Calendar.getInstance();
        if (year < 100) {
            year = 2000 + year;
        }
        ret.set(year, month - 1, day);
        return ret;
    }

    public static Calendar newCalendar(int date) {
        int year = date / 10000;
        int month = (date % 10000) / 100;
        int day = date % 100;

        Calendar ret = Calendar.getInstance();
        ret.set(year, month - 1, day);
        return ret;
    }
}

Related

  1. getDayOfMonth(final Date date)
  2. getFirstDayOfMonth(Date date)
  3. getFirstDayOfMonth(Date date)
  4. getFirstDayOfMonth(java.util.Date date)
  5. getFirstMiddleDayOfMonth(Date date)
  6. getFromDate(boolean invoiceSearchFromFirstDayOfMonth)
  7. getLastDateOfCurMonth()
  8. getLastDay(int year, int month)
  9. getLastDayByMonthWeek(int year, int month, int week)