Reputation: 513
I it seems to be a very stupid question, because Joda-Time is easy to use that there is no explanation about how to use it in its user guide (and I don’t find useful answers on the web).
I try to use the method of Joda-Time which can calculate the duration between two dates. I have to compare the current date with an other date.
I cannot use LocalDateTime
because the class does not exist (so I created it), but I saw that "duration" need to implement ReadableDuration
in the class but this interface does not exist too...
I tried to write :
DateTime dt = new DateTime(juDate);
and
public class LocalDateTime implements ReadableDuration{
public LocalDateTime() {
}
}
I have install Joda-Time by dependency on Maven, I have the 2.9.1 version.
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.1</version>
</dependency>
Can you explain to a newbie how to do, please ?
Upvotes: 2
Views: 18459
Reputation: 1434
Have you done the following in your pom.xml file? :
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.1</version>
</dependency>
Then, after you've added that entry, you have to do mvn clean install from your IDE or command-line. Then it should be available as an import in your project. If you are using another build system, I would like to refer to the following page: http://www.joda.org/joda-time/dependency-info.html.
Don't create the classes yourself, it is a sign that the project is not imported through your build system.
You should be able to do the following in your code above your class declaration:
import org.joda.time.LocalDateTime;
Then you are able to use it.
Edit: As an addition to the above information, I can see that you accepted the answer that suggested that you should switch to Java 8. While in this situation, that might work, but what if you need other packages (dependencies) which are not available through upgrading to a higher Java version?
I suggest you should read upon build systems like Maven and Gradle. Those are mostly used in Java projects. Just playing around with it could give insights.
Upvotes: 3
Reputation: 2989
The time api has been reworked in JDK 8 and resembles a lot Joda-Time (I think Joda-Time is implementation of some JSR).
Citation http://www.joda.org/joda-time/
Joda-Time is the de facto standard date and time library for Java. From Java SE 8 onwards, users are asked to migrate to java.time (JSR-310).
So just create a JDK 8 project and your LocalDate and LocalTime classes should be available in package java.time
After that just follow official oracle tutorial:
http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
GLHF
Upvotes: 6