How to convert date format Using @track with html tag in lwc | How to format today Date in DD/MM/YYYY in lightning web components | Convert String To Current Date In Salesforce LWC


Hey guys, today in this post we are going to learn about How to convert date format Using @track with html tag in LWC.

Displays a date and time based on the locale using lightning-formatted-date-time. Displaying Date and Time Using Type Attributes.

A lightning-formatted-date-time 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 default formatting. The following input values are supported. To know more details about Formatted Date Time, Click Here.


Final Output

convert date format in lwc --


You can download file directly from github by Click Here.


Other related post that would you like to learn in Salesforce


Create Lightning Web Component HTML

Step 1:- Create Lightning Web Component : dateFormatLwc.html

SFDX:Lightning Web Component >> New >> dateFormatLwc.html

βœͺ The Big Announcement: -
As per student's demands, I re-opened my eBook of "Salesforce Tutorial" Limited-time huge discount offer Absolutely 50% Off.
I am thinking to give you discount offer occasion of Gandhi Jayanti for a powerful "Salesforce admin course" where you can Understand from Basic Concepts to advanced label in Salesforce.
πŸ‘‰ So Don't MISS it... (Access Right Now)
πŸ‘‰ Get Huge Discount Offer 50%: - Get eBook

dateFormatLwc.html [Lightning Web Component HTML]

  1.   <template>
  2.     <lightning-card title="Convert Date Format in LWC">
  4.        <p style="margin:0; padding:10px 0 0 35px;  font-size:18px; color:#ff0000;">{forNowDate} </p>
  5. </lightning-card>
  6. </template>


Create Lightning Web Component JavaScript

Step 2:- Create Lightning Web Component : dateFormatLwc.js

SFDX:Lightning Web Component >> New >> dateFormatLwc.js

dateFormatLwc.js [LWC JavaScript File]

  1.   import { LightningElement,track } from 'lwc';
  3. export default class DateFormatLwc extends LightningElement {
  5.     @track forNowDate;
  8.     //Start ConnectedCallback
  10.     connectedCallback() {
  12.         /*Start Date Format*/
  13.             let todayTate = new Date();
  14.             const dateStr = new Intl.DateTimeFormat('en', {
  15.                 year: 'numeric',
  16.                 month: 'short',
  17.                 day: '2-digit'
  18.             })
  19.             const [{value: mo}, , {value: da}, , {value: ye}] = dateStr.formatToParts(todayTate);
  21.             let formatedDate = `${da}-${mo}-${ye}`;
  22.             this.forNowDate=formatedDate;
  23.             console.log('nowdDate### ' , this.v);
  25.             /*End Date Format*/
  27.     }
  29. //End ConnectedCallback
  31. }


Create Lightning Web Component Meta XML

Step 3:- Create Lightning Web Component : dateFormatLwc.js-meta.xml

SFDX:Lightning Web Component >> New >> dateFormatLwc.js-meta.xml

dateFormatLwc.js-meta.xml [LWC Meta Data XML]

  1.   <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="">
  3.     <apiVersion>56.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets> 
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.     </targets>
  10. </LightningComponentBundle>

convert datetime to date in lwc --

Further post that would you like to learn in Salesforce



FAQ (Frequently Asked Questions)

What is the date format in Salesforce LWC?

Salesforce uses the ISO8601 format YYYY-MM-DDThh:mm:ss.SZ for date/time fields, which stores date/time in UTC.

Can you change the date format in Salesforce?

One can use formulas to reformat a date that is generated from Salesforce to another format such as MM/DD/YYYY or MM-DD-YYYY. Create a Formula Field of the type Text to convert Date or Date/Time fields or Functions to the required format.

How do I change the format of a date object?

The function new Date() when called returns the Date object and works like a constructor. Explanation: Here, the above Javascript function new Date() returns the Date object and we get the formatted string as day/ month(in string format) and year.

Related Topics | You May Also Like


Hi, This is Vijay Kumar behind the admin and founder of I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on

Leave a Comment