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);
1 dateString = '2020-04-03 20:30:55';
2
3function formatDate(dateString)
4 {
5 var allDate = dateString.split(' ');
6 var thisDate = allDate[0].split('-');
7 var thisTime = allDate[1].split(':');
8 var newDate = [thisDate[2],thisDate[1],thisDate[0] ].join("-");
9
10 var suffix = thisTime[0] >= 12 ? "PM":"AM";
11 var hour = thisTime[0] > 12 ? thisTime[0] - 12 : thisTime[0];
12 var hour =hour < 10 ? "0" + hour : hour;
13 var min = thisTime[1] ;
14 var sec = thisTime[2] ;
15 var newTime = hour + ':' + min + suffix;
16
17 return newDate + ' ' + newTime;
18 }