Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

Why was java.time (JSR 310) added in Java 8? What problems of java.util.Date, Calendar and SimpleDateFormat does it fix?

java.time was added in Java 8 to replace java.util.Date, Calendar and SimpleDateFormat, which had several deep problems. Date and Calendar are mutable, so shared instances can change unexpectedly; SimpleDateFormat is not thread-safe, while DateTimeFormatter is immutable and thread-safe; Date is really a point in time but prints itself in the JVM's default zone and carries deprecated year, month and day methods; and Calendar counts months from 0 with a verbose API. java.time fixes these with immutable types, a Month enum and 1-based values, and separate types for instants, local dates and times, zoned values, durations and periods.

Why this question is asked

Most new code uses java.time, but legacy APIs, JDBC drivers, older libraries and old code bases still hand us Date and Calendar objects. To work safely across that boundary, we need to know exactly what was wrong with the old classes, because the same bugs appear the moment someone reaches for them again. Interviewers ask this question to see whether we understand the reasons behind the design, not just that the old API is deprecated. In this answer, we will go through the four main problems of the old API with code that shows each one, and see how JSR 310, the specification behind java.time, fixes it.

1Problem 1: Date and Calendar Are Mutable

A java.util.Date has setTime, and Calendar has set and add, which change the object in place. That means any Date stored in a field and shared with other code can be changed by that code, and every class that keeps one must copy it defensively.

Java
Date deadline = new Date();
Task task = new Task(deadline); // Task stores the reference
deadline.setTime(0); // the task's deadline is now 1970-01-01
LocalDate due = LocalDate.of(2026, 11, 30);
due.plusDays(7); // returns a new LocalDate; due is unchanged
System.out.println(due); // 2026-11-30

Every java.time type is immutable. Methods that look like changes, such as plusDays or withMonth, return a new object. So values can be shared, cached and used as map keys with no defensive copies. The only trap left is on our side: ignoring the return value, as the second example shows.

2Problem 2: SimpleDateFormat Is Not Thread-Safe

SimpleDateFormat keeps its working state, including an internal Calendar, inside the formatter object. When two threads use the same instance at the same time, they overwrite each other's state. Because creating one is somewhat expensive, many applications stored one in a static field and shared it, which works in tests and fails under load with wrong dates or exceptions such as NumberFormatException.

Java
static final SimpleDateFormat OLD = new SimpleDateFormat("yyyy-MM-dd");
// called from many request threads at once:
Date d = OLD.parse("2026-11-04"); // sometimes a wrong date, sometimes NumberFormatException
static final DateTimeFormatter NEW = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate ld = LocalDate.parse("2026-11-04", NEW); // 2026-11-04, safe from any number of threads
Step throughTwo threads sharing one SimpleDateFormat
Thread AShared formatterThread B
parse("2026-11-04"): sets internal calendar
parse("1999-01-31"): clears and sets the same calendar
returns a mix of both dates
or throws NumberFormatException

4 messages in order. Play them, or step through them one at a time.

The formatter's working state is a field, so concurrent calls corrupt each other.

DateTimeFormatter is immutable and thread-safe, so a single static final instance can serve every thread. The JDK also ships ready-made ones such as DateTimeFormatter.ISO_LOCAL_DATE and ISO_INSTANT.

3Problem 3: Date Is a Moment That Pretends to Have a Zone

Despite its name, a Date is not a date. It holds a single long, milliseconds since 1970-01-01T00:00Z, so it is really a point in time, like Instant. But toString() formats that moment in the JVM's default time zone, which makes it look as if the Date contains a zone. The same Date prints differently on two servers, and developers often try to change its zone, which is impossible because it never had one.

Date also carries methods such as getYear, getMonth and getHours, deprecated since Java 1.1, which interpret the moment in the default zone and use odd conventions: years are counted from 1900 and months from 0.

Java
Date d = new Date(0L);
System.out.println(d); // Wed Dec 31 19:00:00 EST 1969 on a New York server
// Thu Jan 01 00:00:00 UTC 1970 on a UTC server: same value
Date y = new Date(2026, 0, 15); // deprecated: means year 3926, January 15
System.out.println(Instant.ofEpochMilli(0L)); // 1970-01-01T00:00:00Z, the same on every server

java.time removes the confusion by giving each concept its own type. Instant is the moment and always prints in UTC. Converting to a local view needs an explicit zone, as in instant.atZone(ZoneId.of("America/New_York")), so the zone is always visible in the code.

4Problem 4: Calendar Months Start at 0 and the API Is Verbose

In Calendar, January is 0 and December is 11, while days start at 1. Code that writes cal.set(2026, 2, 1) means March, not February, which surprises nearly everyone. Calendar is also lenient by default, so invalid dates silently roll over instead of failing, and simple tasks need several lines.

Java
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2026, 1, 30); // month 1 is February; 30 February is invalid
System.out.println(cal.getTime()); // Mon Mar 02 00:00:00 ... 2026: silently rolled over
LocalDate.of(2026, Month.FEBRUARY, 30); // DateTimeException: Invalid date 'FEBRUARY 30'
LocalDate.of(2026, 2, 28).plusDays(1); // 2026-03-01

java.time uses natural numbering, 1 for January, offers the Month and DayOfWeek enums for readability, and rejects invalid values with a DateTimeException instead of rolling them over. Its fluent methods, such as plusMonths, withDayOfMonth and the TemporalAdjusters, replace most Calendar arithmetic with one readable line.

5How java.time Separates the Concepts

The deepest fix is conceptual. The old API had one Date class for everything and a Calendar to interpret it. JSR 310, led by the author of the Joda-Time library, gave java.time a separate type for each idea, so the type itself documents what a value means and the compiler stops us mixing them.

One idea, one type
Conceptjava.time typeOld API
Moment on the timelineInstantDate
Calendar dateLocalDateDate at midnight, or Calendar
Time of dayLocalTimeno type
Date and time with zone rulesZonedDateTimeCalendar with TimeZone
Date and time with fixed offsetOffsetDateTimeno type
Time-based amount (hours, seconds)Durationlong milliseconds
Date-based amount (months, days)Periodno type
Formatting and parsingDateTimeFormatter (thread-safe)SimpleDateFormat (not thread-safe)

6Working at the Boundary With Legacy Code

We still meet the old types in older libraries, so java.time provides conversions at the boundary. Date has toInstant() and Date.from(instant), GregorianCalendar has toZonedDateTime() and from(zdt), and TimeZone has toZoneId(). The rule is to convert as soon as an old value enters our code and convert back only where a legacy API requires it, so the inside of the application uses java.time only. Modern JDBC drivers, Hibernate 6 and later, Jackson with its JavaTimeModule (registered automatically by Spring Boot) all handle java.time types directly.

7Follow-up questions

Is java.sql.Date or java.sql.Timestamp any better?

No, they are subclasses of java.util.Date with the same mutability and zone confusion, plus a few odd rules of their own. Since JDBC 4.2 we can read and write LocalDate, LocalDateTime and OffsetDateTime directly with getObject(column, LocalDate.class) and setObject, so new code does not need them.

What about Joda-Time?

Joda-Time was the popular library that fixed these problems before Java 8, and java.time was designed by the same author based on its lessons. Its own documentation advises moving to java.time. Existing Joda-Time code still works, but new code should use java.time.

Is Duration the same as Period?

No. Duration is an exact amount of time in seconds and nanoseconds, such as 90 minutes. Period is a calendar amount in years, months and days, such as one month. Adding one day as Period across a DST change keeps the same local time, while adding 24 hours as Duration may land an hour off.

8Conclusion

In this answer, we saw why java.time was added in Java 8. Date and Calendar are mutable, so shared instances can change behind our backs, while java.time types are immutable. SimpleDateFormat is not thread-safe, while DateTimeFormatter is. Date is a moment that prints itself in the default zone and carries confusing deprecated field methods, while Instant prints in UTC and zones are explicit. Calendar counts months from 0 and rolls invalid dates over, while java.time uses 1-based months, enums and strict validation. Above all, java.time separates instants, local dates and times, zoned values, durations and periods into distinct types.

What to say in the interviewAbout 90 seconds aloud

Open with

java.time, from JSR 310 in Java 8, replaced an API with several deep problems. First, Date and Calendar are mutable: setTime, set and add change the object in place, so a Date stored in a field can be changed by whoever else holds it, and every class needs defensive copies. java.time types are immutable and methods like plusDays return new objects.

Then, if they want more

Second, SimpleDateFormat is not thread-safe because it keeps its parsing state, including a Calendar, in the instance, so the common static shared formatter gives wrong dates or NumberFormatException under load; DateTimeFormatter is immutable and thread-safe, so a static final instance is fine.

Third, Date is confusing: it is really just milliseconds since 1970, a moment, but toString prints it in the JVM's default zone, so it looks as if it has a zone, and its deprecated getYear and getMonth methods count years from 1900 and months from zero.

Fourth, Calendar months start at zero, so set 2026, 2, 1 means March, it is lenient so February 30 silently becomes March 2, and the API is verbose. java.time uses one-based months, a Month enum, and throws DateTimeException for invalid dates.

Most importantly, it separates the concepts into types: Instant for moments, LocalDate and LocalTime for calendar and clock values, ZonedDateTime and OffsetDateTime for zoned values, and Duration and Period for amounts.

About this answer

Last updated
12 November 2026
Versions it names
Java 8, Hibernate 6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Why was java.time (JSR 310) added in Java 8? What problems of java.util.Date, Calendar...": https://scrivio-interview-library.netlify.app/java/date-and-time/3e1b8c6a6f/