Consider immutable forms for dates

Some programmers prefer to store date fields not as java.util.Date objects, but in an immutable form. For example, you could use: (The DateTime class in the date4j library also addresses the issue, but when JDK 8+ is available, it likely shouldn't be used.)

Reasons for preferring an immutable representation:


Here, a LocalDate is used to encapsulate a date:

import java.time.LocalDate;
import java.util.Objects;

public class Film {
  public static void main(String... args) {
    Film film = new Film("The Lobster", LocalDate.parse("2015-10-16"));

  public Film(String name, LocalDate releasedOn){ = name;
    this.releasedOn = releasedOn;
  public String getName() {
    return name;
  public LocalDate getReleasedOn() {
    return releasedOn;

  private String name;
   Immutable. Has no time-zone information.
   The time-zone is simply treated as implicit, according to 
   the context.
  private LocalDate releasedOn;
  private static void log(Object thing){

See Also :
Defensive copying
Immutable objects