how to display "last updated on" in my AEM page? | Community
Skip to main content
Level 2
August 3, 2017
Solved

how to display "last updated on" in my AEM page?

  • August 3, 2017
  • 5 replies
  • 7598 views

so I  wanna display the "last updated on" base on the changes made to the content (excluding header/footer).

Any ideas how this can be done? on our AEM, the header and footer is a separate component and I should like to display the "last updated on" on the footer.

I've searched the net but didn't see anything useful.

Thanks!

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 susheel

Hi,

What do you mean by above statement. Do you want to show it on footer html ?

If you are trying to read the last modified date of footer node. Just add the below code in your footer component:

Last Updated on ${'dd-MM-yyyy' @ format=properties['jcr:lastModified']}
(or)

Last Updated on ${'dd-MM-yyyy HH:mm' @ format=properties['jcr:lastModified'], timezone='GMT+05:30'}

Go through this link as well : htl-spec/SPECIFICATION.md at master · Adobe-Marketing-Cloud/htl-spec · GitHub

Update:

The above code works on 6.3 but not on 6.2 .

You can do as below:

package com.project;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import com.adobe.cq.sightly.WCMUsePojo;

public class DateFormatter extends WCMUsePojo {

    private String formattedDate;

    @Override

    public void activate() {

    Calendar date  = get("date", Calendar.class);

    String format =  get("format",String.class);

    SimpleDateFormat formatter = new SimpleDateFormat(format);

    formattedDate = formatter.format(date.getTime());

    }   

    public String getFormattedDate() {

        return formattedDate;

    }

}

<sly data-sly-use.date="${'com.project.DateFormatter' @ date=properties['jcr:lastModified'],format='dd/MM/yyyy'}">

    ${date.formattedDate}

</sly>

5 replies

susheel
susheelAccepted solution
Level 5
August 3, 2017

Hi,

What do you mean by above statement. Do you want to show it on footer html ?

If you are trying to read the last modified date of footer node. Just add the below code in your footer component:

Last Updated on ${'dd-MM-yyyy' @ format=properties['jcr:lastModified']}
(or)

Last Updated on ${'dd-MM-yyyy HH:mm' @ format=properties['jcr:lastModified'], timezone='GMT+05:30'}

Go through this link as well : htl-spec/SPECIFICATION.md at master · Adobe-Marketing-Cloud/htl-spec · GitHub

Update:

The above code works on 6.3 but not on 6.2 .

You can do as below:

package com.project;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import com.adobe.cq.sightly.WCMUsePojo;

public class DateFormatter extends WCMUsePojo {

    private String formattedDate;

    @Override

    public void activate() {

    Calendar date  = get("date", Calendar.class);

    String format =  get("format",String.class);

    SimpleDateFormat formatter = new SimpleDateFormat(format);

    formattedDate = formatter.format(date.getTime());

    }   

    public String getFormattedDate() {

        return formattedDate;

    }

}

<sly data-sly-use.date="${'com.project.DateFormatter' @ date=properties['jcr:lastModified'],format='dd/MM/yyyy'}">

    ${date.formattedDate}

</sly>

Level 3
April 11, 2019

Hi Susheel,

I want to display the last modified date of page in which i put this footer node.Please let me know

smacdonald2008
Level 10
April 11, 2019

You would implement a HTL component using Java WCMUSEPOJO and obtain this node property using Java code. Then display the value via HTL - as explained the correct response of this thread.

Level 3
April 11, 2019

How to obtain node property in java? The above code displays the footer node last modified date. But i need the page last modified date

manikanthar1295
Level 5
April 12, 2019

Hi,

You can use Node Property like below.

String nodePath = "/content/community-components/en/comments/jcr:content/content/title";

try

{

Node node = null;

NodeIterator nodes =null;

String result="";

resource = slingRequest.getResourceResolver().getResource(nodePath);

   if(resource != null)

  {

  node = resource.adaptTo(Node.class);

  

   if(node.hasProperty("jcr:lastModifiedBy"))

  {

  result=node.getProperty("jcr:lastModifiedBy").getValue().getString();

  out.print(result);

  

  }

  }

}

catch(Exception e)

{

out.print(e);

}

Regards

Manikantha R