Add Apache Commons Lang support

This commit is contained in:
anujgaud 2023-11-29 01:56:50 +05:30 committed by GitHub
parent ecba15ffb7
commit 118195d996
1 changed files with 9 additions and 0 deletions

View File

@ -14,6 +14,8 @@ import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.ISODateTimeFormat; import org.joda.time.format.ISODateTimeFormat;
import org.apache.commons.lang3.time.FastDateFormat;
public class LocalDateToISO { public class LocalDateToISO {
public String formatUsingDateTimeFormatter(LocalDate localDate) { public String formatUsingDateTimeFormatter(LocalDate localDate) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
@ -32,4 +34,11 @@ public class LocalDateToISO {
org.joda.time.format.DateTimeFormatter formatter = ISODateTimeFormat.dateTime(); org.joda.time.format.DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
return formatter.print(localDate.toDateTimeAtStartOfDay(DateTimeZone.UTC)); return formatter.print(localDate.toDateTimeAtStartOfDay(DateTimeZone.UTC));
} }
public String formatUsingApacheCommonsLang(LocalDate localDate) {
Date date = Date.from(localDate.atStartOfDay().toInstant(ZoneOffset.UTC));
String formattedDate = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", TimeZone.getTimeZone("UTC"))
.format(date);
return formattedDate;
}
} }