java

How to check today date is first day of the current month


How to find out if the today date is the first day of the current month. Say, today is 24/05/2015 but it is not first day of the month. what is the best way to get the output.


Solution

  • Extract the "day" part and compare it to 1:

    if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == 1) {
        System.out.println ("Today is the first day of the month");
    }