JSFiddle - React, Tailwind, and code Playground

by Dan Mathisen

HTML

<div id="console">
</div>

JavaScript

var d = new Date("11/01");
//get the month

var month = d.getMonth();

//get the day

//convert day to string

var day = d.getUTCDate().toString();

//get the year

var year = d.getFullYear();

//pull the last two digits of the year.substr(-2);

year = year.toString();

//increment month by 1 since it is 0 indexed

//converts month to a string

month = (month + 1).toString();

//if month is 1-9 pad right with a 0 for two digits

if (month.length === 1){

	month = "0" + month;

	}
//if day is between 1-9 pad right with a 0 for two digits

if (day.length === 1){

day = "0" + day;

}



if (isNaN(d)) {

	return "000000";
}

//return the string "MMddyy"

var consoleEl = document.getElementById('console');
consoleEl.textContent = month +"/"+ day +"/"+ year;