Does any one able to retrieve cq:lastReplicated in JSON as String? | Community
Skip to main content
February 7, 2024
Question

Does any one able to retrieve cq:lastReplicated in JSON as String?

  • February 7, 2024
  • 4 replies
  • 891 views

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 :
Output coming inJSON as :
 
"publishDate""java.util.GregorianCalendar[time=1707236418257,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id=\"GMT-05:00\",offset=-18000000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2024,MONTH=1,WEEK_OF_YEAR=6,WEEK_OF_MONTH=2,DAY_OF_MONTH=6,DAY_OF_YEAR=37,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=11,HOUR_OF_DAY=11,MINUTE=20,SECOND=18,MILLISECOND=257,ZONE_OFFSET=-18000000,DST_OFFSET=0]",
Please let me know if I am missing any steps .






4 replies

kautuk_sahni
Community Manager
Community Manager
September 17, 2024

@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.

Kautuk Sahni
Umesh_Thakur
Community Advisor
Community Advisor
September 17, 2024

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

HeenaMadan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 17, 2024

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; }

 

 
then string date : 2024-09-17 20:02:03.470 +0000
Hope this helps!
lavishvasuja
Level 3
October 19, 2025

Hi @pmhaem 

You can retrieve cq:lastReplicated as a Calendar and then format it to a string before adding it to your JSON object. This approach not only gives you the correct string now but also keeps flexibility for any future date manipulations.

ValueMap properties = hit.getProperties(); if (properties.get("cq:lastReplicated") != null) { Calendar lastReplicated = properties.get("cq:lastReplicated", Calendar.class); String formattedDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(lastReplicated.getTime()); contentObject.addProperty("publishDate", formattedDate); }

Here the formattedDate will be in a clean string format like:
2025-10-19T11:20:18-0500

This approach is preferable if you might need to manipulate the date later (e.g., adding/subtracting days, timezone adjustments) while still allowing easy JSON output.

Hope this helps!