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);