Check a given date is first day of month using Joda API


In this post, I will show you how to check whether a given date is first day of the month using Joda API. Joda API is a date time API which provides useful methods for data and time management in Java applications.


Java 8 or 12, Joda API 2.10.3 (or 2.7), Junit 4.12

Build using Gradle

If you want to build application using gradle script – build.gradle, then you can use the following build script.

In the below build script we have included Joda API and Junit API for date time and running test cases respectively.

plugins {
    id 'java-library'
sourceCompatibility = 12
targetCompatibility = 12
repositories {
dependencies {
    implementation 'joda-time:joda-time:2.10.3'
    testImplementation 'junit:junit:4.12'

Build using Maven

If you want to build the application using maven file – pom.xml, then you can use the following build file.

<project xmlns="" xmlns:xsi=""
        <!-- joda date time -->
        <!-- junit -->

Checking Day of Month

Create a utility class with utility method to check a given date is first day of month using Joda API.

package com.roytuts.joda;
import org.joda.time.DateTime;
public final class JodaDateUtils {
	public static boolean isDateFirstDayOfTheMonth(final DateTime dateTime) {
		return dateTime.getDayOfMonth() == 1;

Junit Testing

Create Junit test case to test the above 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");

Testing the Application

Run the above Junit class, you will get the below output:


Source Code

You can download source code.

Thanks for reading.

Leave a Reply

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