September 28, 2020

Java Sample Code to convert a calendar to string object





//2020-06-05T00:00:00.000Z
public static String calendarToStr(Calendar calendar) {
try {
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);

Instant instant = calendar.getTime().toInstant();

LocalDateTime localDateTime = instant.atZone(ZoneId.of(DEFAULT_ZONE_ID, ZoneId.SHORT_IDS)).toLocalDateTime();

String formattedDate = inputFormatter.format(localDateTime);

return formattedDate;


                catch (Exception e) {
e.printStackTrace();
}


return null;
}

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments