Skip to content

Instantly share code, notes, and snippets.

@briannhinton
Created July 8, 2022 15:07
Show Gist options
  • Save briannhinton/86638f9789e8c42210bfb67122446f41 to your computer and use it in GitHub Desktop.
Save briannhinton/86638f9789e8c42210bfb67122446f41 to your computer and use it in GitHub Desktop.
Convert a date to a string, and reorder the output
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