JS獲取前一天年月日
<script> function myDate() { var mydate = new Date(); var year = mydate.getFullYear(); var month = mydate.getMonth() + 1; if (month < 10) month = "0" + month; var day = mydate.getDate() ; if(day == "1") { if(month=="1") {year = year - 1; month = 12;}else { month = month - 1 ; if(month=="1"||month=="3"||month=="5"||month=="7"||month=="8"||month=="10"||month=="12") {day = "31"} if(month=="4"||month=="6"||month=="9"||month=="11") {day = "30"} if(month=="2") { if (year % 400 == 0) { day = 29;}else {if (year % 4==0&&(year % 100 != 0)) { day = 29; } day = 28; } } } }else { day = day -1; } if (month < 10) {month = "0" + month;} if(day<10) {day = "0" + day;} document.getElementById("datetimepicker").value = year + "/" + month + "/" + day; document.getElementById("datetimepicker2").value = year + "/" + month + "/" + day; } </script>