Created
July 8, 2022 15:07
-
-
Save briannhinton/86638f9789e8c42210bfb67122446f41 to your computer and use it in GitHub Desktop.
Convert a date to a string, and reorder the output
This file contains 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
const formatDate = (inputDate) => { | |
const date = new Date(inputDate); | |
if (!isNaN(date.getTime())) { | |
const day = date.getDate().toString(); | |
const month = (date.getMonth() + 1).toString(); | |
// Months use 0 index. | |
return (month[1] ? month : '0' + month[0]) + '/' + | |
(day[1] ? day : '0' + day[0]) + '/' + | |
date.getFullYear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment