Skip to content

Instantly share code, notes, and snippets.

@geekelo
Created January 3, 2024 19:54
Show Gist options
  • Save geekelo/fda1df37d87496215f3d2299f9024945 to your computer and use it in GitHub Desktop.
Save geekelo/fda1df37d87496215f3d2299f9024945 to your computer and use it in GitHub Desktop.
Date Formatter
function formatDate(inputDate) {
const months = [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
];
const [year, month, day] = inputDate.split('-');
const monthAbbreviation = months[parseInt(month, 10) - 1];
return `${parseInt(day, 10)} ${monthAbbreviation}, ${year}`;
}
// Example usage:
const formattedDate = formatDate('2023-12-26');
console.log(formattedDate); // Output: '26 Dec, 2023'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment