Expand my Community achievements bar.

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



Arun Patidar

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