Java Day of Month getFromDate(boolean invoiceSearchFromFirstDayOfMonth)

Here you can find the source of getFromDate(boolean invoiceSearchFromFirstDayOfMonth)

Description

get From Date

License

Open Source License

Declaration

public static Date getFromDate(boolean invoiceSearchFromFirstDayOfMonth) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static Date getFromDate(boolean invoiceSearchFromFirstDayOfMonth) {
        if (invoiceSearchFromFirstDayOfMonth) {
            Calendar calendar = Calendar.getInstance();
            int month = calendar.get(Calendar.MONTH);
            calendar.set(Calendar.MONTH, month - 6);
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar.getTime();
        } else {//from  w  w w.j ava 2 s .co m
            Calendar calendar = Calendar.getInstance();
            int today = calendar.get(Calendar.DAY_OF_MONTH);
            int month = calendar.get(Calendar.MONTH);
            if (calendar.getActualMaximum(Calendar.DAY_OF_MONTH) > today) {
                calendar.set(Calendar.MONTH, month - 6);
                calendar.set(Calendar.DAY_OF_MONTH, today);
            } else {
                calendar.set(Calendar.MONTH, month - 6 - 1);
                calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
            }
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar.getTime();
        }
    }
}

Related

  1. getFirstDayOfMonth(Date date)
  2. getFirstDayOfMonth(Date date)
  3. getFirstDayOfMonth(java.util.Date date)
  4. getFirstMiddleDayOfMonth(Date date)
  5. getFistDayOfMonth(Date date)
  6. getLastDateOfCurMonth()
  7. getLastDay(int year, int month)
  8. getLastDayByMonthWeek(int year, int month, int week)
  9. getLastDayInMonth(int year, int month)