Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
December 4, 2023
If you want to format dates using built-in methods of javascript then you can use Intl.DateTimeFormat() of javascript.
Here’s how you can format date to ’mm dd, yy’ format using Intl.DateTimeFormat():
Code:
const formatDate = (date) => { const options = { year: '2-digit', month: 'short', day: 'numeric', }; const formatter = new Intl.DateTimeFormat('en-US', options); const parts = formatter.formatToParts(date); // Extract the formatted parts of date to rearrange them const month = parts.find(part => part.type === 'month').value; const day = parts.find(part => part.type === 'day').value; const year = parts.find(part => part.type === 'year').value; return `${month} ${day}, ${year}`; } const myDate = new Date(); // You can replace this with your date const formattedDate = formatDate(myDate); console.log(formattedDate);
Below are variety of options you can use to format date according to your requirements:
For Year:
‘numeric’: 2023
‘2-digit’: 23
For Month:
‘numeric’: 1, 2, 3, …
‘2-digit’: 01, 02, 03, …
‘narrow’: J, F, M, …
‘short’: Jan, Feb, Mar, …
‘long’: January, February, March, …
For Day:
‘numeric’: 1, 2, 3, …
‘2-digit’: 01, 02, 03, …
For Weekday:
‘narrow’: S, M, T, …
‘short’: Sun, Mon, Tue, …
‘long’: Sunday, Monday, Tuesday, …
For Hour:
‘numeric’: 1, 2, 3, …
‘2-digit’: 01, 02, 03, …
For Minute:
‘numeric’: 0, 1, 2, …
‘2-digit’: 00, 01, 02, …
For Second:
‘numeric’: 0, 1, 2, …
‘2-digit’: 00, 01, 02, …
You can also use the popular moment.js library to easily format your dates.