Normally if I wanted to get the date I could just do something like
var d = new Date();
console.log(d);
The problem with doing that, is when I
Just use the built-in .toISOString()
method like so: toISOString().split('T')[0]
. Simple, clean and all in a single line.
var date = (new Date()).toISOString().split('T')[0];
document.getElementById('date').innerHTML = date;
Please note that the timezone of the formatted string is UTC rather than local time.