How to get cq:lastModified in jcr:content from HTL? | Community
Skip to main content
bhoang
Level 4
April 11, 2018
Solved

How to get cq:lastModified in jcr:content from HTL?

  • April 11, 2018
  • 8 replies
  • 8214 views

Hello,

I want to get cq:lastModified from a jcr:content. I tried there code but it doesn't work.

<div class="last-modify">

     <p>ABC ${properties.cq:lastModified}</p>

     <p>XYZ ${currentPage.properties.cq:lastModified}</p>

     <p>cdg ${currentPage.properties.jcr:lastModified}</p>

</div>

How to do that in singhtly?

Thank you so much,

BienHV

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

Here is that page prop - notice it is Feb 16

HTL Code:

<div>

<p>This is your AEM HTML Template Language component:</p>

      <h1>${properties.heading}</h1>

       <p>${properties.description}</p>

       <p>The following values are the resource types added to the dialog</p>

       <p><b>Selected Path value:</b> ${properties.path}</p>

       <p>

            <b>Date:</b>

                  ${'yyyy-MM-dd HH:mm:ss.SSSXXX' @ format=properties.startdate, timezone='UTC'}

        </p>

        <p>

            <b>Size:</b> ${properties.size}

        </p>

        <p>

            <b>Checkbox:</b> ${properties.show}

        </p>

        <p>

        ${pageProperties['cq:lastModified'].getTime.toString}

        </p>

</div>

Output --

8 replies

Bhuwan08
Level 2
April 11, 2018

Try -  ${pageProperties['cq:lastModified'].getTime.toString}

smacdonald2008
smacdonald2008Accepted solution
Level 10
April 11, 2018

Here is that page prop - notice it is Feb 16

HTL Code:

<div>

<p>This is your AEM HTML Template Language component:</p>

      <h1>${properties.heading}</h1>

       <p>${properties.description}</p>

       <p>The following values are the resource types added to the dialog</p>

       <p><b>Selected Path value:</b> ${properties.path}</p>

       <p>

            <b>Date:</b>

                  ${'yyyy-MM-dd HH:mm:ss.SSSXXX' @ format=properties.startdate, timezone='UTC'}

        </p>

        <p>

            <b>Size:</b> ${properties.size}

        </p>

        <p>

            <b>Checkbox:</b> ${properties.show}

        </p>

        <p>

        ${pageProperties['cq:lastModified'].getTime.toString}

        </p>

</div>

Output --

bhoang
bhoangAuthor
Level 4
April 13, 2018

Thanks you for your help,

How to format for cq:lastModifield date?

${pageProperties['cq:lastModified'].getTime.toString}

with the code above I get the string as Thu Apr 12 14:51:52 ICT 2018.

How to format for date cq:lastModified as mm-dd-yyyy h:m:s?

example 04-12-2018 14:51:52 UTC

Thank you so much,

Vijayalakshmi_S
Level 10
April 13, 2018

Hi,

We need to do the date formatting at java end using SimpleDateFormat with desired pattern/format.

Level 3
April 25, 2019

Hi,

We need to do the date formatting at java end using SimpleDateFormat with desired pattern/format. How to fetch the cq:lastmodified in java?

arunpatidar
Community Advisor
Community Advisor
April 25, 2019

Hi,

You can use sling model or WCMUsePojo to fetch page properties or properties in java.

Example :

@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })

public class TestModel {

  @Inject

  private Page resourcePage;

  public String getLastModifiedDate() {

     SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");

     dateFormat.setTimeZone(resourcePage.getLastModified().getTimeZone());

     return dateFormat.format(resourcePage.getLastModified().getTime());

  }

}

You need Page object to retrieve the page properties in Sling Model.

Page ("The Adobe AEM Quickstart and Web Application.")

Arun Patidar
December 29, 2023

How write HTL of this Java code

Level 3
April 25, 2019

how do i display this date in htl?

arunpatidar
Community Advisor
Community Advisor
April 25, 2019

Hi,

You can directly use date in the page using below

${'MM/dd/yyyy HH:mma' @ format=currentPage.lastModified}

Or You can use Java. Please check below :

HTL Date Formatting

Arun Patidar