diff --git a/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/localdatetoiso/LocalDateToISO.java b/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/localdatetoiso/LocalDateToISO.java index 7ef5c9bf56..969006a720 100644 --- a/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/localdatetoiso/LocalDateToISO.java +++ b/core-java-modules/core-java-8-datetime-2/src/main/java/com/baeldung/localdatetoiso/LocalDateToISO.java @@ -9,6 +9,10 @@ import java.util.Date; import org.apache.commons.lang3.time.DateFormatUtils; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.format.DateTimeFormat; + public class LocalDateToISO { public String formatUsingDateTimeFormatter(LocalDate localDate) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX"); @@ -22,4 +26,11 @@ public class LocalDateToISO { String formattedDate = dateFormat.format(utilDate); return formattedDate; } + + public String formatUsingJodaTime(org.joda.time.LocalDate localDate) { + DateTime dateTime = localDate.toDateTimeAtStartOfDay(DateTimeZone.UTC); + org.joda.time.format.DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); + String formattedDate = formatter.print(localDate); + return formattedDate; + } }