Hi,
Does anyone able to retrieve cq:lastReplicated in JSON output as String? I am using Query builder to retrieve query result.
ValueMap properties = hit.getProperties()
if (properties.get("cq:lastReplicated") != null) {
LOGGER.info("Published Date" + properties.get("cq:lastReplicated").toString());
contentObject.addProperty("publishDate", properties.get("cq:lastReplicated").toString());
}
Output coming as :
Please let me know if I am missing any steps .
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
@kapil_rajoria @HeenaMadan @Umesh_Thakur @h_kataria When you have a chance, could you please review this question and offer your perspective? I'd love to hear your insights.
Hi @pmhaem ,
It seems you are getting a bit differently, use proper get method like:
Date lastReplcationDate = properties.get("cq:lastReplicated", Date.class);
here you can use either dataFormate or DateTimeFormatter to convert
the date to string before adding it to JSON.
you can refer below link:
https://stackoverflow.com/questions/5683728/convert-java-util-date-to-string
Hope this helps
Umesh Thakur
Hi @pmhaem
Use below to get cq:lastReplicated value and then convert date to string as per your dateformat before adding to jsonobject.
ValueMap properties = hit.getProperties();
if (properties.get("cq:lastReplicated") != null) {
java.util.Date replicatedDate = properties.get("cq:lastReplicated", Date.class);
//now convert Date to string
Strig strDate = convertDateToString(replicatedDate);
}
public static String convertDateToString(Date input){
SimpleDateFormat outputFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z");
outputFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String formattedDateStr = outputFormatter.format(input);
System.out.println("Formatted Date String: " + formattedDateStr);
return formattedDateStr;
}
Views
Likes
Replies
Views
Likes
Replies