Created
January 3, 2024 19:54
-
-
Save geekelo/fda1df37d87496215f3d2299f9024945 to your computer and use it in GitHub Desktop.
Date Formatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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