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);
1function pad2(n) {
2 return (n < 10 ? '0' : '') + n;
3}
4
5var date = new Date();
6var month = pad2(date.getMonth()+1);//months (0-11)
7var day = pad2(date.getDate());//day (1-31)
8var year= date.getFullYear();
9
10var formattedDate = day+"-"+month+"-"+year;
11alert(formattedDate); //28-02-2021
1dformat = [d.getDate(), d.getMonth() + 1, d.getFullYear()].join('/') + ' ' + [d.getHours(),d.getMinutes(),d.getSeconds()].join(':');
1 var d='dd/mm/yy hh:MM:ss';
2 var d1=d.split(" ");
3 var date=d1[0].split("/");
4 var time=d1[1].split(":");
5 var dd=date[0];
6 var mm=date[1]-1;
7 var yy=date[2];
8 var hh=time[0];
9 var min=time[1];
10 var ss=time[2];
11 var fromdt= new Date("20"+yy,mm-1,dd,hh,min,ss);
12