Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joda DateTime vs Instant

Tags:

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?

like image 574
DD. Avatar asked Jan 03 '12 22:01

DD.


People also ask

Is Joda DateTime deprecated?

So the short answer to your question is: YES (deprecated).

What is the replacement of Joda-time?

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.

What is Joda-time used for?

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.

What is Joda-time format?

Joda-Time provides a comprehensive formatting system. There are two layers: High level - pre-packaged constant formatters. Mid level - pattern-based, like SimpleDateFormat.


1 Answers

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?

like image 135
skaffman Avatar answered Oct 25 '22 15:10

skaffman