I'm using Joda
, and I'm making a class to store the timestamp for a transaction and persist to a DB. Should I be using an Instant
or a DateTime
?
So the short answer to your question is: YES (deprecated).
Correct Option: D. In java 8,we are asked to migrate to java. time (JSR-310) which is a core part of the JDK which replaces joda library project.
Joda-Time is the most widely used date and time processing library, before the release of Java 8. Its purpose was to offer an intuitive API for processing date and time and also address the design issues that existed in the Java Date/Time API.
Joda-Time provides a comprehensive formatting system. There are two layers: High level - pre-packaged constant formatters. Mid level - pattern-based, like SimpleDateFormat.
Use whichever one best fits your model. Instant
is a representation of a millisecond timestamp value, DateTime
is a calendar-based object. Each one can be easily converted into the other, so there's no need to restrict your model according what the database needs.
So you need to ask yourself - what data am I actually modelling? Is it a year/month/day/hour/minute/second/etc value, or is it just an arbitrary moment in time with no particular meaning?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With