js获取当前日期:
var ayear = new Date().getFullYear(); // 获取当前年 var amonth = new Date().getMonth() + 1; //获取当前月 var aday = new Date().getDate(); //获取当前天
1:js对年月进行比较
var jhny = ""; var ayear = new Date().getFullYear(); var amonth = new Date().getMonth() + 1; var adate = new Date((ayear + "-" + amonth + "-01").replace("-", "/")); for (var z = 0; z < trs.length; z++) { if (trs[z].cells[7].getElementsByTagName("INPUT")[0].value != "") { var aadate = new Date((trs[z].cells[7].getElementsByTagName("INPUT")[0].value + "-01").replace("-", "/")); if (aadate < adate) { if (jhny == "") { jhny = 1; } else { jhny = jhny+","+(z+1); } } } } if (jhny!="") { alert("第"+jhny+"行收入年月不能小于当前年月!!"); return false; }
2:C#获取几天几号
int day = Convert.ToInt32(DateTime.Now.ToString("dd")); if (day > 15) { //大于15号需要做的处理 }