【发布时间】:2014-10-18 17:00:17
【问题描述】:
我在我的 Web 应用程序中使用 spring-mvc 和 bootstrap。在页面中,我有 2 个字段供用户输入开始日期时间和结束日期时间,这是我从 bootstrap-datetimepicker.js 中获取的 https://github.com/smalot/bootstrap-datetimepicker
这很好用,但现在我需要包含验证,startdate-time 总是大于 enddate-time,我也使用 jquery.validate.min.js 进行表单验证,但我无法比较2个时间戳,我试过下面的代码
$.validator.addMethod("budgetgreaterThan",
function(value, element, params) {
alert(value);
value=value.slice(0,-6);
if (!/Invalid|NaN/.test(new Date(value))) {
return new Date(value) >= new Date($(params).val());
}
return isNaN(value) && isNaN($(params).val())
|| (Number(value) > Number($(params).val()));
},'Must be greater than {0}.');
rules:
{
budgetgreaterThan: '#startdate'
}
messages:
{
budgetgreaterThan:"Delivery date and Collect date should be proper"
}
这里的时间戳值是这种格式"YYYY-MM-DD hhhh:mm:ss"
谁能告诉我如何做到这一点?
【问题讨论】:
标签: jquery twitter-bootstrap smalot-datetimepicker