We can now write the following HelloJoda program!
import org.joda.time.LocalDate;
public class HelloJoda {
public static void main(String [] args) {
LocalDate today = LocalDate.now();
System.out.println("Hello Joda! Today's date is: " + today);
}
}
Which will output something like this:
Hello Joda! Today's date is: 2016-11-26
Download the JAR and add it to the classpath for your Java project
If you are using a build tool like Maven or Gradle:
Maven
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.6</version>
</dependency>
Gradle
Add the following line to the dependencies
closure inside your build.gradle
:
compile 'joda-time:joda-time:2.9.6'
Joda-Time is a robust alternative to the Java date and time classes.
Prior to Java SE 8, the standard Java date and time classes like java.util.Calendar
are difficult to use and prone to errors. Joda-Time emerged as the de-facto standard library for date and time manipulation in many open-source-projects.
However, starting with Java SE 8 the package java.time
(JSR-310) is available and users are asked to migrate to the same since Joda-Time is now in maintenance mode.
You want to manipulate dates and times and:
java.time
(JSR-310) classes.Since the standard Joda-Time library can inflate the memory-footprint of apps, consider using joda-time-android. This is a fork optimized for Android development, and also contains a Joda-Time port of Android's native DateUtils
.