Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

Date formatting in sightly

Avatar

Level 3

Hi there,

 

Does anyone know how to format cq:lastModified  to RFC3339 format in Sightly?

 

Thanks in advance.

 

Harpreet

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
3 Replies

Avatar

Correct answer by
Community Advisor

Hi,

You can't do this in sightly, you need to do in java/sling model

https://stackoverflow.com/questions/49752149/how-do-i-convert-2018-04-10t040000-000z-string-to-datet... 

Avatar

Community Advisor

Hi @hptarora ,

 

In Sling Model, something like below-

 

@Model(adaptables = Resource.class)
public class MyModel {

@Inject
private String myDate;

/**
* @return the myDate
*/
public String getMyDate() {

String lastModified = //Get the String
return new SimpleDateFormat("dd-M-yyyy hh:mm:ss").format(lastModified);
}

}

Avatar

Community Advisor

@hptarora 

 

<sly data-sly-use.htl="com.aem.models.HTLSightlySlingModal"></sly>
<div>${'yyyy-MM-dd HH:mm' @format=htl.publishDate , timezone='UTC'}</div>
<div>${'EEEE, d MMM y' @format=htl.publishDate , timezone='UTC', locale='en'}</div>

 

where  publishDate — returns Calender object

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now