[SalesForce] Is it possible to format date rendered by the ui:outputDate Lightning Component

I am currently wanting to output a date returned by my server-side controller to a Lightning component. I know that in VisualForce markup, you have the ability to format dates returned to the VisualForce page as mentioned in this post. However, I am not sure how to do this in a Lightning component? It seems you can perform locale formatting at a higher level as show here in the developer guide, but I am just wanting to format a single date output. The output type is a "Date" primitive type and not DateTime or I might use the DateTime.format() method in the server-side controller to do the formatting and do something like DateTime.format('MMM, d') which is the format that I need (i.e. Jul 05).

Has anyone had any experience doing this in the Lightning component? I have had some issues getting it to work correctly in the server-side controller. The date that is sent back from the server-side controller is a day behind the actual record date.

Thanks!

Best Answer

The ui:outputDate component has an attribute called langLocale which you can pass a country code to and an attribute called format that should follow the java.text.SimpleDateFormat interface. Thus, you should be able to do

<ui:outputDate format="MMM d" value={!v.date}/>
Related Topic