I once worked on a product where we made the mistake of representing a date of birth as an instant.
This was one of those "tiny" design errors that we were still dealing with years later.
The problem was that you couldn't reliably show it in the UI as the user changed time zone; it was error-prone to convert on the backend, because of developers working in different time zones to where the server was running. It sort-of worked in a single time zone, but as the product was extended to other time zones, it just became a total headache.
An instant is a point on the timeline; a local date is a range of times (and not a well-defined range of times, in the sense that it can represent different ranges of instants in different time zones). They represent different things.
If you want to represent a date, store a date. And I don't mean a java.util.Date
, which is really an instant.
Use a LocalDate
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…