ACP*_*ACP 3 javascript validation date
我有两个日期18-Aug-2010
和19-Aug-2010
这种格式.如何查找哪个日期更大?
您需要创建自定义解析函数来处理所需的格式,并获取要比较的日期对象,例如:
function customParse(str) {
var months = ['Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'],
n = months.length, re = /(\d{2})-([a-z]{3})-(\d{4})/i, matches;
while(n--) { months[months[n]]=n; } // map month names to their index :)
matches = str.match(re); // extract date parts from string
return new Date(matches[3], months[matches[2]], matches[1]);
}
customParse("18-Aug-2010");
// "Wed Aug 18 2010 00:00:00"
customParse("19-Aug-2010") > customParse("18-Aug-2010");
// true
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16034 次 |
最近记录: |