Salesforce Lightning Formatted DateTime
Biswajeet
February 21, 2018 No Comments on Salesforce Lightning Formatted DateTime
lightning:formattedDateTime
component displays formatted date and time. This component uses the Intl.DateTimeFormat JavaScript object to format date values. The locale set in the app’s user preferences determines the formatting.
Below are the supported input values for lightning:formattedDateTime
component:
- Date object
- ISO8601 formatted string
- Timestamp
Lightning Component:
<!--Sample.cmp--> <aura:component> <!--Declare Attribute--> <aura:attribute name="currentDate" type="Date"/> <!--Declare Handlers--> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <!--Component Start--> <div class="slds-m-around_xx-large"> <lightning:formattedDateTime aura:id="dt" value="{!v.currentDate}" month="short" day="numeric" year="numeric" hour="2-digit" minute="2-digit" second="2-digit" hour12="true" timeZone="{!$Locale.timezone}"/> </div> <!--Component End--> </aura:component>
Lightning JS Controller:
({ doInit : function(component, event, helper) { var today = new Date(); component.set('v.currentDate', today); } })
Output:
The above example will return a value in this “Feb 18, 2018, 10:37:13 AM” format.