joda-time
Joda-Time is the widely used replacement for the Java date and time classes prior to Java SE 8.
Top Related Projects
General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Google core libraries for Java
A date and time library based on the C++11/14/17 <chrono> header
Quick Overview
Joda-Time is a quality replacement for the Java date and time classes prior to Java 8. It provides a comprehensive and intuitive API for handling dates, times, and durations. While it's no longer actively developed due to the introduction of java.time in Java 8, it remains widely used in legacy projects and Android development.
Pros
- Intuitive and easy-to-use API for date and time operations
- Immutable and thread-safe design
- Extensive support for different calendar systems and time zones
- Better performance compared to Java's built-in date/time classes prior to Java 8
Cons
- No longer actively developed (maintenance mode)
- Not necessary for projects using Java 8 or later, as java.time provides similar functionality
- Can lead to dependency conflicts in projects mixing old and new Java versions
- Slightly steeper learning curve compared to the simpler (but less capable) java.util.Date
Code Examples
- Creating and formatting a date:
DateTime now = new DateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("MMMM dd, yyyy HH:mm:ss");
String formatted = now.toString(fmt);
System.out.println(formatted);
- Performing date arithmetic:
DateTime today = new DateTime();
DateTime nextWeek = today.plusWeeks(1);
Days daysBetween = Days.daysBetween(today, nextWeek);
System.out.println("Days until next week: " + daysBetween.getDays());
- Working with different time zones:
DateTime londonTime = new DateTime(DateTimeZone.forID("Europe/London"));
DateTime tokyoTime = londonTime.withZone(DateTimeZone.forID("Asia/Tokyo"));
System.out.println("London: " + londonTime);
System.out.println("Tokyo: " + tokyoTime);
Getting Started
To use Joda-Time in your project, add the following dependency to your Maven pom.xml
:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.12.5</version>
</dependency>
For Gradle, add this to your build.gradle
:
implementation 'joda-time:joda-time:2.12.5'
Then, import the necessary classes in your Java file:
import org.joda.time.*;
import org.joda.time.format.*;
You can now start using Joda-Time in your project!
Competitor Comparisons
General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Pros of jackson-databind
- More versatile, handling various data formats beyond just JSON
- Actively maintained with frequent updates and improvements
- Extensive customization options for serialization and deserialization
Cons of jackson-databind
- Steeper learning curve due to its broader feature set
- Can be overkill for simple JSON processing tasks
- Larger library size, potentially increasing application footprint
Code Comparison
jackson-databind:
ObjectMapper mapper = new ObjectMapper();
MyObject obj = mapper.readValue(jsonString, MyObject.class);
String json = mapper.writeValueAsString(obj);
joda-time:
DateTime dateTime = new DateTime(2023, 5, 15, 10, 30);
String formatted = dateTime.toString("yyyy-MM-dd HH:mm:ss");
While both libraries serve different purposes, this comparison highlights their core functionalities. jackson-databind focuses on data binding and serialization, while joda-time specializes in date and time manipulation. jackson-databind offers more flexibility for general data processing, but joda-time provides a simpler API for working with dates and times specifically.
Google core libraries for Java
Pros of Guava
- Broader utility library covering collections, caching, concurrency, and more
- Actively maintained with regular updates and new features
- Extensive documentation and community support
Cons of Guava
- Larger dependency size due to its comprehensive nature
- Steeper learning curve for developers new to the library
- Some features may overlap with standard Java libraries in newer versions
Code Comparison
Joda-Time
DateTime now = new DateTime();
DateTime tomorrow = now.plusDays(1);
Period period = new Period(now, tomorrow);
Guava
Instant now = Instant.now();
Instant tomorrow = now.plus(Duration.ofDays(1));
Duration duration = Duration.between(now, tomorrow);
Summary
Joda-Time is a specialized library for date and time operations, while Guava is a more comprehensive utility library. Joda-Time offers a simpler API for date-time manipulations, but Guava provides a wider range of utilities beyond just date-time handling. The choice between the two depends on the specific needs of the project and whether a focused date-time library or a broader utility suite is required.
A date and time library based on the C++11/14/17 <chrono> header
Pros of date
- C++ library, offering better performance and lower-level control
- Header-only implementation, simplifying integration into projects
- Supports C++11 and later, leveraging modern C++ features
Cons of date
- Less comprehensive feature set compared to joda-time
- Smaller community and ecosystem around the library
- Limited documentation and examples available
Code Comparison
date:
#include "date/date.h"
using namespace date;
auto d = 2023_y/3/14;
auto t = make_time(12, 30, 0);
auto dt = sys_days(d) + t;
joda-time:
import org.joda.time.DateTime;
DateTime dt = new DateTime(2023, 3, 14, 12, 30, 0);
Summary
date is a modern C++ library focusing on performance and simplicity, while joda-time is a more established Java library with a broader feature set. date is ideal for C++ projects requiring efficient date/time handling, whereas joda-time is better suited for Java applications needing comprehensive date/time functionality and extensive documentation.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Joda-Time
Joda-Time provides a quality replacement for the Java date and time classes. The design allows for multiple calendar systems, while still providing a simple API. The 'default' calendar is the ISO8601 standard which is used by XML. The Gregorian, Julian, Buddhist, Coptic, Ethiopic and Islamic systems are also included. Supporting classes include time zone, duration, format and parsing.
Joda-time is no longer in active development except to keep timezone data up to date.
From Java SE 8 onwards, users are asked to migrate to java.time
(JSR-310) - a core part of the JDK which replaces this project.
For Android users, java.time
is added in API 26+.
Projects needing to support lower API levels can use the ThreeTenABP library.
As a flavour of Joda-Time, here's some example code:
public boolean isAfterPayDay(DateTime datetime) {
if (datetime.getMonthOfYear() == 2) { // February is month 2!!
return datetime.getDayOfMonth() > 26;
}
return datetime.getDayOfMonth() > 28;
}
public Days daysToNewYear(LocalDate fromDate) {
LocalDate newYear = fromDate.plusYears(1).withDayOfYear(1);
return Days.daysBetween(fromDate, newYear);
}
public boolean isRentalOverdue(DateTime datetimeRented) {
Period rentalPeriod = new Period().withDays(2).withHours(12);
return datetimeRented.plus(rentalPeriod).isBeforeNow();
}
public String getBirthMonthText(LocalDate dateOfBirth) {
return dateOfBirth.monthOfYear().getAsText(Locale.ENGLISH);
}
Joda-Time is licensed under the business-friendly Apache 2.0 licence.
Documentation
Various documentation is available:
- The home page
- Two user guides - quick and full
- The Javadoc
- The FAQ list
- Information on downloading and installing Joda-Time including release notes
Releases
Release 2.12.7 is the current latest release. This release is considered stable and worthy of the 2.x tag. It depends on JDK 1.5 or later.
Available in the Maven Central repository
Maven configuration:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.12.7</version>
</dependency>
Gradle configuration:
compile 'joda-time:joda-time:2.12.7'
Related projects
Related projects at GitHub:
- https://github.com/JodaOrg/joda-time-hibernate
- https://github.com/JodaOrg/joda-time-jsptags
- https://github.com/JodaOrg/joda-time-i18n
Other related projects:
For enterprise
Available as part of the Tidelift Subscription.
Joda and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.
If you want the flexibility of open source and the confidence of commercial-grade software, this is for you.
Support
Please use Stack Overflow for general usage questions. GitHub issues and pull requests should be used when you want to help advance the project.
Any donations to support the project are accepted via OpenCollective.
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
Development and Contributions
Joda-Time is developed using standard GitHub tools.
A checkstyle file is available, and PRs must comply with it.
The project can be built using Apache Maven, such as mvn clean install
.
Continuous Integration takes place using GitHub Actions.
Units tests are written in JUnit and run as part of the build and continuous integration.
Changes via PR must include appropiate test coverage.
Note that Joda-Time is considered to be a largely âfinishedâ project. No major enhancements are planned. If using Java SE 8, please migrate to java.time (JSR-310).
Release process
- Update version (pom.xml, README.md, index.md, MANIFEST.MF, changes.xml)
- Commit and push
- Ensure on Java SE 8
mvn clean deploy -Doss.repo -Dgpg.passphrase=""
- Website will be built and released by GitHub Actions
Top Related Projects
General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Google core libraries for Java
A date and time library based on the C++11/14/17 <chrono> header
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot