Add milliseconds

This commit is contained in:
anujgaud 2023-11-29 01:49:35 +05:30 committed by GitHub
parent dd89145547
commit fcc9c4c6ce
1 changed files with 5 additions and 6 deletions

View File

@ -12,25 +12,24 @@ import org.apache.commons.lang3.time.DateFormatUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.ISODateTimeFormat;
public class LocalDateToISO {
public String formatUsingDateTimeFormatter(LocalDate localDate) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
String formattedDate = localDate.atStartOfDay().atOffset(ZoneOffset.UTC).format(formatter);
return formattedDate;
}
public String formatUsingSimpleDateFormat(LocalDate date) {
Date utilDate = Date.from(date.atStartOfDay(ZoneOffset.UTC).toInstant());
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
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;
org.joda.time.format.DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
return formatter.print(localDate.toDateTimeAtStartOfDay(DateTimeZone.UTC));
}
}