file.setLastModified() method in ResourceTree SitemapGenerator
While creating sitemap using org.apache.sling.sitemap api, I am able to create sitemap by using
ResourceTreeSitemapGenerator class
but in my sitemap.xml file I am getting date in <lastmod>2024-08-29T11:07:56.308Z</lastmod> this format, while i want in <lastmod>2024-05-10</lastmod> format.
I tried to covert it by dateformatted but the issue with code is
final Url url = sitemap.addUrl(fullUrl);
final Calendar lastmod = Optional.ofNullable(page.getLastModified())
.orElse(page.getContentResource().getValueMap().get(JcrConstants.JCR_CREATED, Calendar.class));
if (lastmod != null) {
Instant lastModifiedInstant = lastmod.toInstant();
// Define the desired date format
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// Format the date according to your requirement (e.g., 2024-04-30)
String formattedDate = lastModifiedInstant.atZone(ZoneId.systemDefault()).format(formatter);
// Now, set the last modified date in the sitemap URL
url.setLastModified(formattedDate);
// Optionally, log or print the formatted date if needed
COMMON_LOGGER.logInfo(CLASS_NAME, "Formatted Last Modified Date: " + formattedDate);
}
in url.setLastModified method it expected date to be in Instant format.
Note: with Instant type date comes in ISO 8601 format while i only want to show yyyy-MM-dd