JSFiddle - React, Tailwind, and code Playground

by kenwals

HTML

<div id="res">res</div>

JavaScript

function formatDate(date) {
    var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2) month = '0' + month;
    if (day.length < 2) day = '0' + day;

    return [year, month, day].join('-');
}
let today = new Date();

document.getElementById('res').innerHTML =  formatDate(today) ;