* {
font-family: monospace;
}
//a simple date formatting function
function dateFormat(inputDate, format) {
//parse the input date
const date = new Date(inputDate);
//extract the parts of the date
const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();
//replace the month
format = format.replace("MM", month.toString().padStart(2,"0"));
//replace the year
if (format.indexOf("yyyy") > -1) {
format = format.replace("yyyy", year.toString());
} else if (format.indexOf("yy") > -1) {
format = format.replace("yy", year.toString().substr(2,2));
}
//replace the day
format = format.replace("dd", day.toString().padStart(2,"0"));
return format;
}
console.log('Converted date: '+ dateFormat('2021-12-10', 'MM-dd-yyyy'));
This Pen doesn't use any external CSS resources.