Hello Friends, In this post, you will see an example that helps you set today's date in lighting component. so let's see the example.
Set today's date in lightning component
For this example we used lightning:input type="date" element.
SetTodaysDate.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >SetTodaysDateController.js
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<lightning:card title="Set Today Date" iconName="action:announcement">
<lightning:input style="margin-left:20px;width:20%" type="date" aura:id="txtDate" dateStyle="short" label="Today's Date" value=""/>
</lightning:card>
</aura:component>
({
doInit : function(component, event, helper) {
var today = $A.localizationService.formatDate(new Date(), "YYYY-MM-DD");
component.find("txtDate").set("v.value",today);
}
})
Output:
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.
0 Comments
Post a Comment