function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shatrughna SalunkeShatrughna Salunke 

Date format in lightning controller

Hi below is my code and l'am looking for chnage the date format 

JS Controller
         var previouslySearchedDate=[];   
         var temp = getList;    // here we are getting list of record 
           
            for(var i=0 ; i<temp.length;i++)
            {
              if(!$A.util.isUndefinedOrNull(temp[i].previouslySearched))
                {
                  var previousDate=(temp[i].previouslySearched=== undefined ? "" : temp[i].previouslySearched+'');
                  temp[i].previouslySearchedDate=previousDate;
                }

             }

CMP
     <div class="assoc-label slds-grid slds-wrap">Previously searched on: {!r.previouslySearchedDate}

Current output: 
    12/1/2000:T0000 ,11/10/2012:T0000

Now , I'm  looking as  below
     12/1/2000,11/10/2012
RituSharmaRituSharma
You may use lightning:formattedDateTime component to display the date/time in desired way:
https://developer.salesforce.com/docs/component-library/bundle/lightning:formattedDateTime/example
AbhishekAbhishek (Salesforce Developers) 
A 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 Salesforce user preferences determines the formatting.

Try the code snippet here (https://www.biswajeetsamal.com/blog/tag/date-format/).

For your reference, you can check this too (https://salesforce.stackexchange.com/questions/143107/date-formatting-to-dd-mm-yyyy).


Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.