logo

Get First Date of Current Month using Calendar

Java Code Examples for java.util.Calendar

Get First Date of Current Month using Calendar.

package simplesolution.dev;

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

public class CalendarFirstDayOfMonthExamples {

    public static void main(String... args) {
        Calendar calendar = Calendar.getInstance();
        Date currentDate = new Date();
        calendar.setTime(currentDate);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        Date firstDateOfMonth = calendar.getTime();

        System.out.println(firstDateOfMonth);
    }
}

Happy Coding 😊