1var today = new Date();
2var dd = String(today.getDate()).padStart(2, '0');
3var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
4var yyyy = today.getFullYear();
5
6today = mm + '/' + dd + '/' + yyyy;
7document.write(today);
1let date_ob = new Date();
2
3// adjust 0 before single digit date
4let date = ("0" + date_ob.getDate()).slice(-2);
5
6// current month
7let month = ("0" + (date_ob.getMonth() + 1)).slice(-2);
8
9// current year
10let year = date_ob.getFullYear();
11
12// current hours
13let hours = date_ob.getHours();
14
15// current minutes
16let minutes = date_ob.getMinutes();
17
18// current seconds
19let seconds = date_ob.getSeconds();
20
21// prints date & time in YYYY-MM-DD HH:MM:SS format
22console.log(year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds);
1var date_format = new Date();
2
3document.write(innerHTML = date_format.getMonth()+'/'+ date_format.getDate()+'/'+date_format.getFullYear());
1dformat = [d.getDate(), d.getMonth() + 1, d.getFullYear()].join('/') + ' ' + [d.getHours(),d.getMinutes(),d.getSeconds()].join(':');