Expand my Community achievements bar.

DD-MMM format in Content Fragment

Avatar

Level 4

Hi Team

 

I have created a content fragment and my requirement is to have to date format in DD-MMM.

In the crx/de when I save the displayFormat as DD-MMM and on the UI when I select data it is displaying correctly like ex: 02-Dec however valueFormat is giving error when crx/de is having format as DD-MMM format.  However if the default valueFormat is given like YYYY-MM-DD[T]HH:mm:ss.000Z then no error. but required is to display like DD-MMM or YYYY. 

please advise. Attaching xml for your reference.

 

<policy_period_end
jcr:primaryType="nt:unstructured"
sling:resourceType="dam/cfm/models/editor/components/datatypes/datepicker"
displayedFormat="DD-MMM"
fieldLabel="Policy Period End"
listOrder="5"
metaType="date"
name="policy_period_end"
renderReadOnly="false"
showEmptyInReadOnly="true"
type="datetime"
valueFormat="DD-MMM"
valueType="calendar/datetime">
<granite:data
jcr:primaryType="nt:unstructured"
typeHint="Date"/>
</policy_period_end>
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Community Advisor

Hi @Prashardan 

 

The date on crx/de is stored with type property Date and it requires you to save format in defined format which is YYYY-MM-DD[T]HH:mm:ss.000Z that is date should contain timeZone information also.

I think you should only keep display format as required like DD-MMM but remove the valueFormat as by default it will be saved with correct date along with timezone. Now, if you need to access date in code and required the specific Date format, then the format can be converted to required one using SimpleDateFormat Class.

 

Hope it helps!

Thanks

Nupur