javascript date format mm/dd/yyyy
let date_ob = new Date();
// adjust 0 before single digit date
let date = ("0" + date_ob.getDate()).slice(-2);
// current month
let month = ("0" + (date_ob.getMonth() + 1)).slice(-2);
// current year
let year = date_ob.getFullYear();
// prints date in YYYY-MM-DD format
console.log(year + "-" + month + "-" + date);
<!DOCTYPE HTML>
<html>
<head>
<title>
JavaScript
| How to get current formatted date dd/mm/yyyy.
</title>
</head>
<body style="text-align:center;"
id="body">
<h1 style="color:green;">
GeeksForGeeks
</h1>
<p id="GFG_UP"
style="font-size: 15px;
font-weight: bold;">
</p>
<button onclick="gfg_Run()">
get Date
</button>
<p id="GFG_DOWN"
style="color:green;
font-size: 20px;
font-weight: bold;">
</p>
<script>
var el_up = document.getElementById("GFG_UP");
var el_down = document.getElementById("GFG_DOWN");
var today = new Date();
el_up.innerHTML = today;
function gfg_Run() {
var date = today.toJSON().slice(0, 10);
var nDate = date.slice(8, 10) + '/'
+ date.slice(5, 7) + '/'
+ date.slice(0, 4);
el_down.innerHTML = nDate;
}
</script>
</body>
</html>