Java Day of Month getToDate(boolean invoiceSearchFromFirstDayOfMonth)

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

Description

get To Date

License

Open Source License

Declaration

public static Date getToDate(boolean invoiceSearchFromFirstDayOfMonth) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static Date getToDate(boolean invoiceSearchFromFirstDayOfMonth) {
        if (invoiceSearchFromFirstDayOfMonth) {
            Calendar calendar = Calendar.getInstance();
            int month = calendar.get(Calendar.MONTH);
            calendar.set(Calendar.MONTH, month - 1);
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
            return toMidnight(calendar.getTime());
        } else {//from   w  w  w  .  j  a  v a  2 s.c o m
            return new Date();
        }
    }

    public static Date toMidnight(Date date) {
        if (date == null) {
            return null;
        }
        Date returnDate = date;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        returnDate = calendar.getTime();
        return returnDate;
    }
}

Related

  1. getLastDayOfMonth(String year, String month)
  2. getLastdayOfMonth(String year, String month)
  3. getLastDayOfMonth(String year, String month)
  4. getLastDayOfTheMonth(String dateOfString)
  5. getLastDayOfXMonth(Date date, String xMonth)
  6. getWeekOfFirstDayOfMonth(Date date)
  7. getWeekOfLastDayOfMonth(Date date)
  8. isGivenDayOfMonth(java.util.Date date, int dayOfMonth)
  9. isSameDayOfMonth(Date dt1, Date dt2)