Formatting and Extracting Date in React
To extract Day, Month and Year using toLocalString
Table of contents
No headings in the article.
Sample date formatting for React Javascript using toLocalString() function
const ExpenseDate = () => {
const date = new Date(2021,3,12);
const year = date.getFullYear();
const month = date.toLocaleString('en-US', { month: 'long' });
const day = date.toLocaleString('en-US', { day: '2-digit' });
return (
<div className="expense-date">
<div className="expense-date__year">{year}</div>
<div className="expense-date__month">{month}</div>
<div className="expense-date__day">{day}</div>
</div>
);
}
More formatting information and be referred here: developer.mozilla.org/en-US/docs/Web/JavaSc..