日期比较
CS方法
//比较开始时间和结束时间 public bool CheckDate(string strStartDate, string strEndDate) { bool flag = false; string tempStartDate = ConvertDateFormat(strStartDate).ToString(); string tempEndDate = ConvertDateFormat(strEndDate).ToString();
if (tempStartDate!=""&&tempEndDate!="") { DateTime startDate = DateTime.Parse(tempStartDate); DateTime EndDate = DateTime.Parse(tempEndDate); //结束时间大于或者等于开始时间,则返回为真 if (DateTime.Compare(EndDate, startDate)>=0) { flag=true; } } return flag;
} //日期格式转换 “YYYY-MM-DD”转换为“DD/MM/YYYY” public string ConvertDateFormat(string strDate) { char[] a ="-".ToCharArray(); string[] TempDate = strDate.Split(a); string strConvertDate = ""; if (TempDate.Length==3) { strConvertDate = TempDate[1].ToString() + "/" + TempDate[2].ToString() + "/" + TempDate[0].ToString();
} return strConvertDate; } |
CS方法
JS方法
JS方法
function compareDate(StartDate,EndDate) { var StartMonth = StartDate.substring(5,StartDate.lastIndexOf ("-")); var StartDay = StartDate.substring(StartDate.length,StartDate.lastIndexOf ("-")+1); var StartYear = StartDate.substring(0,StartDate.indexOf ("-")); var EndMonth = EndDate.substring(5,EndDate.lastIndexOf ("-")); var EndDay = EndDate.substring(EndDate.length,EndDate.lastIndexOf ("-")+1); var EndYear = EndDate.substring(0,EndDate.indexOf ("-")); if (Date.parse(StartMonth+"/"+StartDay+"/"+StartYear) > Date.parse(EndMonth+"/"+EndDay+"/"+EndYear)) { return true; } else { return false; } } |
如果山不向我走来,我就向山走去!
![](http://www.cnblogs.com/Emoticons/baimantou/202015214.gif)