Java, Software Development

Get First And Last Dates Of Current Quarter Using Joda Time

This post shows how to come up with the first and last dates of the current quarter using Joda time. Although we can do it in Java 8 and above using the Time API, Joda Time is an alternative.

Joda Time, JDK, and IDE Requirements

We use the following items in this post.

  • Intellij 2022.1 (Ultimate Edition)
  • Java Development Kit 17

Next, we update the pom.xml to include the following dependency. Note that this version of the Joda time requires at least JDK 17 to work.

Java Codes To Get First And Last Dates In The Current Quarter

Then, we craft codes to use Joda time to get the first and last dates in the current quarter. It has one static method that returns an array with two dates. Also, the date with index 0 represents the first date in the quarter while the other represents the other date.

Note that we use a class name from Joda time similar to a Java Time API – LocalDate. However, these two classes are different.

Test Joda Time To Get First And Last Dates

Consider the following Java main method.

When we run all the codes, we get the following output.

And that is how we get the first and last dates in the current quarter using Joda Time.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like