In this post, I will show you how to check whether a given date is first day of the month using joda date time API.


The following configurations are required in order to run the application

JDK 1.8
Have maven installed and configured
Joda date API dependency in pom.xml

Now we will see the below steps how to create a maven based Java project in Eclipse

Step 1. Create a standalone maven project in Eclipse

Go to File -> New -> Other. On popup window under Maven select Maven Project. Then click on Next. Select the workspace location – either default or browse the location. Click on Next. Now in next window select the row as highlighted from the below list of archtypes and click on Next button.


Now enter the required fields (Group Id, Artifact Id) as shown below

Group Id : com.roytuts
Artifact Id : java

Step 2. Modify the pom.xml file as shown below.

<project xmlns="" xmlns:xsi=""




        <!-- joda date time -->
        <!-- junit -->


Step 4. Create a utility class to create utility method

package com.roytuts.joda;

import org.joda.time.DateTime;

public class JodaDateUtils {

    public static boolean isDateFirstDayOfTheMonth(final DateTime dateTime) {
        return dateTime.getDayOfMonth() == 1;


Step 5. Create Junit test case to test the method

package com.roytuts.joda;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Test;

public class JodaDateUtilsTest {

    private final DateTimeFormatter dtf = DateTimeFormat.forPattern("dd-MM-yyyy");

    public void testIsDateFirstDayOfTheMonth() {
        DateTime dt = new DateTime();
        dt = dtf.parseDateTime("01-02-2016");
        dt = dtf.parseDateTime("01-01-2016");
        dt = dtf.parseDateTime("05-02-2016");


Step 6. Run the above Junit, you will get the below output


Thanks for reading.


Leave a Reply

Your email address will not be published. Required fields are marked *