<script type="text/javascript"> function getLastDate() { var date = new Date(); var month = date.getMonth() + 1; var day = date.getDate(); var hh = date.getHours(); var mm = date.getMinutes(); var ss = date.getSeconds(); var year = date.getFullYear(); alert(year); var ym; var year1; day = day - 10; if (day <= 0) { day = mygetday(day, month, year); var months = mygetmonth(month); ym = months.split(","); year1 = ym[0]; day = FormatDate(day); month = FormatDate(ym[1]); return year1 + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss; } else { return year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss; } } // 获取某一天的日期 function mygetday(day, month, year) { var daynum = 30; if (month == 2 || month == 4 || month == 6 || month == 8 || month == 9 || month == 1 || month == 11) { daynum = 31; } else if (month == 3) { if (year % 4 == 0) { daynum = 29; } else { daynum = 28; } } day = daynum + day; return day; } // 获取某一天的月份 function mygetmonth(month) { var year = new Date().getFullYear(); if (month == 1) { month = 12; year = year - 1; } else { month = month - 1; } return year + "," + month; } function FormatDate(d) { if (d.toString().length == 1) { d = "0" + d; } return d; } $(function () { $(‘#birthday‘).datetimebox(‘setValue‘, getLastDate()); }); </script> <script type="text/javascript"> function getLastDate() { var date = new Date(); //获取当前时间 var month = date.getMonth() + 1; var day = date.getDate(); var hh = date.getHours(); var mm = date.getMinutes(); var ss = date.getSeconds(); var year = date.getFullYear(); alert(year); var ym; var year1; day = day - 10; //获取十天前的时间 if (day <= 0) { day = mygetday(day, month, year); var months = mygetmonth(month); ym = months.split(","); year1 = ym[0]; day = FormatDate(day); month = FormatDate(ym[1]); return year1 + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss; } else { return year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss; } } // 获取某一天的日期 function mygetday(day, month, year) { var daynum = 30; if (month == 2 || month == 4 || month == 6 || month == 8 || month == 9 || month == 1 || month == 11) { daynum = 31; } else if (month == 3) { if (year % 4 == 0) { daynum = 29; } else { daynum = 28; } } day = daynum + day; return day; } // 获取某一天的月份 function mygetmonth(month) { var year = new Date().getFullYear(); if (month == 1) { month = 12; year = year - 1; } else { month = month - 1; } return year + "," + month; } function FormatDate(d) { if (d.toString().length == 1) { d = "0" + d; } return d; } //测试填充文本框 $(function () { $(‘#birthday‘).datetimebox(‘setValue‘, getLastDate()); }); </script>
时间: 2024-11-01 10:42:27