Change the date formate from "2024-08-22" to "22 Aug - 2024"
const formatDate = (dateString) => {
// Split the date string into year, month, and day
const [year, month, day] = dateString.split("-");
// Create a Date object from the splitted parts
const dateObject = new Date(dateString);
// Format the month using an array of month names
const monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
const monthName = monthNames[dateObject.getMonth()];
// Construct the formatted date string
const formattedDate = `${parseInt(day, 10)} ${monthName} - ${year}`;
setDate(formattedDate);
};
0 Comments