自己写的一个函数,可以对混合的日期格式进行判断如“2008年9月23日12时36分4秒”和"2008-9-23 13:37:4"。
1
<
script
>
2
//这里是测试代码
3
var start = 0;
4
var end = 0;
5
start = new Date().getTime();
6
var a = "2008年02-03日20时36分4秒"
7
var b = "2008-02-03 20:36:4"
8
document.write("比较结果为:"+comparDate(b,a)+"<br>")
9
end = new Date().getTime();
10
document.write("耗时:"+(end - start) / 1000 + "sec");
11
//测试代码结束
12![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
function comparDate(date1, date2)
{
14
var patton1 = /[日秒]/g;
15
var patton2 = /[年月-]/g;
16
var patton3 = /[时分:]/g;
17
date1 = date1.replace(patton1," ").replace(patton2,"/").replace(patton3,":");
18
date2 = date2.replace(patton1," ").replace(patton2,"/").replace(patton3,":");
19
document.write(date1 + "<br>");
20
document.write(date2 + "<br>");
21
var Temp = (Date.parse(date1) - Date.parse(date2)); // 24*60*60*1000
22
var result = Temp > 0 ? 1 : Temp == 0 ? 0 : -1;
23
return result;//返回1是大于,返回0是等于,返回-1是小于
24
}
25
</
script
>
26
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)