1let date_ob = new Date();
2
3// current date
4// adjust 0 before single digit date
5let date = ("0" + date_ob.getDate()).slice(-2);
6
7// current month
8let month = ("0" + (date_ob.getMonth() + 1)).slice(-2);
9
10// current year
11let year = date_ob.getFullYear();
12
13// current hours
14let hours = date_ob.getHours();
15
16// current minutes
17let minutes = date_ob.getMinutes();
18
19// current seconds
20let seconds = date_ob.getSeconds();
21
22// prints date in YYYY-MM-DD format
23console.log(year + "-" + month + "-" + date);
24
25// prints date & time in YYYY-MM-DD HH:MM:SS format
26console.log(year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds);
27
28// prints time in HH:MM format
29console.log(hours + ":" + minutes);
30