How to check if the current date is the first of the month

I am trying to write a function that includes checking if the current date is the first of the months, for example, 01/03/2015, and then run something depending on if that is the case.

It doesn't matter if this is a date or calendar object, I just want to check if the current code launch date is the first month

+4
source share
2 answers

There is a recipient here:

public boolean isFirstDayofMonth(Calendar calender){
    if(calender == null)
        return false;

    int dayOfMonth = calender.get(Calendar.DAY_OF_MONTH);
    return (dayOfMonth == 1);
}
+7
source
public static boolean isFirstDayOfTheMonth(Date dateToday){
    Calendar c = new GregorianCalendar();
    c.setTime(dateToday );

    if (c.get(Calendar.DAY_OF_MONTH) == 1) {
      return true;
    }
    returns false;
}
0
source

All Articles