java.time
Other answers are true when displaying strategies for fixing values inside your objects.
Let me also recommend that you use modern java.time classes, not scary heritage classes. Use Instant instead of Date . Instead of Calendar use ZonedDateTime .
The java.time classes are created as immutable objects. Methods such as plus… , minus… , to… and with produce a new object, leaving the original intact. Classes do not have customization methods.
Bonus tip: in your own immutable classes, you might find it useful to follow the method naming patterns set by the java.time classes.
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
Using the JDBC driver compatible with JDBC 4.2 or later, you can exchange java.time objects directly with your database. No need for strings or java.sql. * Classes.
Where to get java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .
source share