baeldung-articles : BAEL-7403 (#15573)

* baeldung-articles : BAEL-7403

Convert Joda-Time DateTime to Date and Vice Versa

* (Move) baeldung-articles : BAEL-7403

Move the code to this module.
This commit is contained in:
DiegoMarti2 2024-01-10 00:13:10 +02:00 committed by GitHub
parent 5136e7349b
commit a94bf971f5
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package com.baeldung.jodadatetimetostandarddate;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class JodaDateTimeToDateAndViceVersaUnitTest {
@Test
public void givenJodaDateTime_whenConvertingToJavaDate_thenConversionIsCorrect() {
DateTime jodaDateTime = new DateTime();
java.util.Date javaDate = jodaDateTime.toDate();
assertEquals(jodaDateTime, new DateTime(javaDate));
}
@Test
public void givenJavaDate_whenConvertingToJodaDateTime_thenConversionIsCorrect() {
java.util.Date javaDate = new java.util.Date();
DateTime jodaDateTime = new DateTime(javaDate);
assertEquals(javaDate, jodaDateTime.toDate());
}
}