0

I am trying to use the ActivityDateTime field of Event object in a lightning:formattedDateTime and it doesn't show anything. If I use a Date attribute of the component it works fine so I suppose the problem is with the field.

<aura:iteration items="{!v.events}" var="ev">
<lightning:formattedDateTime value="{!ev.ActivityDateTime}"/>
</aura:iteration>
2
  • What's the question ?
    – Jarvis
    Commented May 30, 2017 at 14:44
  • Sorry, the question is why it doesn't work, if that field is Date field, am I missing something?
    – Acabo
    Commented May 30, 2017 at 14:46

1 Answer 1

0

Acabo, There is no issue in "lightning:formattedDateTime" the behavior is working as expected.

Your {!ev.ActivityDateTime} would return Salesforce Date/DateTime Object like follows 2015-08-04T01:07:12.000Z.

However this is not the format that lightning:formattedDateTime takes. The document clearly states

This component uses the Intl.DateTimeFormat JavaScript object to format date values.

Reference : https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_formattedDateTime.htm

So you must do something as follows to get your formatted date.

Component:

<lightning:formattedDateTime aura:id="ltngDate" value="" />

Controller :

var d = new Date();
component.find("ltngDate").set("v.value",d);

This way we will be passing the Javascript Date Object not the Salesforce Object, The value also takes unix timestamp as arguments.

If we pass salesforce Date/DateTime Objects we will get the following error.

Error

2
  • 1
    You are right. Thanks. Anyway, finally I have used ui:outputDateTime that works fine with the salesforce object
    – Acabo
    Commented May 30, 2017 at 15:29
  • Good choice, given that the above is still in beta =)
    – Sumuga
    Commented May 30, 2017 at 15:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .