javascript how do i get just the yyyy-mm-dd only with new Date() code example
Example 1: javascript format date yyyy-mm-dd
let today = new Date()
today.toISOString().split('T')[0]
Example 2: get current date javascript yyyy-mm-dd
function pad2(n) {
return (n < 10 ? '0' : '') + n;
}
var date = new Date();
var month = pad2(date.getMonth()+1);//months (0-11)
var day = pad2(date.getDate());//day (1-31)
var year= date.getFullYear();
var formattedDate = year+"-"+month+"-"+day;
alert(formattedDate); //2021-02-28