how to display "last updated on" in my AEM page? | Community
Skip to main content
Level 2
Aug 3, 2017 7:01 AM UTC
Solved

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

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.
susheel
susheelAccepted solution
Level 5
Aug 3, 2017 7:11 AM UTC

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

manikanthar1295
Level 5
Apr 12, 2019 4:27 AM UTC

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

Translate
Level 3
Apr 11, 2019 6:53 PM UTC

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

Translate
smacdonald2008
Level 10
Apr 11, 2019 6:38 PM UTC

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.

Translate
Level 3
Apr 11, 2019 6:14 PM UTC

Hi Susheel,

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

Translate
susheel
susheelAccepted solution
Level 5
Aug 3, 2017 7:11 AM UTC

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>

Translate