How to get current formatted date dd/mm/yyyy in Javascript and append it to an input [duplicate]

I hope this is what you want:

const today = new Date();
const yyyy = today.getFullYear();
let mm = today.getMonth() + 1; // Months start at 0!
let dd = today.getDate();

if (dd < 10) dd = '0' + dd;
if (mm < 10) mm = '0' + mm;

today = dd + "https://stackoverflow.com/" + mm + "https://stackoverflow.com/" + yyyy;

document.getElementById('DATE').value = today;

How do I get the current date in JavaScript?

Leave a Comment