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 dateString = "20120515";
2var year = dateString.substring(0,4);
3var month = dateString.substring(4,6);
4var day = dateString.substring(6,8);
5
6var date = new Date(year, month-1, day);
7