1var today = new Date();
2var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
3var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
4var dateTime = date+' '+time;
5
1var today = new Date();
2var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
3
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);
1var today = new Date();
2var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
3//var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
4var dateTime = date+' '+time;
5The dateTime variable contains result as:
6
72018-8-3 //11:12:40
1var today = new Date();
2 var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
3 console.log(date)
4// output 2021-7-9