Pat*_*lka 5 javascript kendo-asp.net-mvc
美好的一天,我需要将两个日期之间的天数输入两个kendo.DateTimePickers.
我的解决方案总是以NaN值结束.RentStartDate和RentEndDate作为DateTime存储在db中.
感谢您的意见.
<script>$("#RentEndDate").change(function () {
var startDate = kendo.toString($("#RentStartDate").data("kendoDateTimePicker").value(), "dd.MM.yyyy");
var endDate = kendo.toString($("#RentEndDate").data("kendoDateTimePicker").value(), "dd.MM.yyyy");
alert(calculate(startDate, endDate));
});
function calculate(first, second) {
var diff = Math.round((second - first) / 1000 / 60 / 60 / 24);
return diff;
}
Run Code Online (Sandbox Code Playgroud)
CreateOrders.cshtml
<h4>Termín p?j?ení</h4>
<div class="t-col t-col-6 t-col-xs-12 t-col-sm-12 t-col-md-12 col-sm-6">
<label for="rentStartPicker">P?j?it od</label>
@(Html.Kendo().DatePickerFor(model => model.RentStartDate).Name("rentStartPicker").HtmlAttributes(new { style = "height:28px;", required = "required", validationmessage = "Vyberte datum" }))
</div>
<div class="t-col t-col-6 t-col-xs-12 t-col-sm-12 t-col-md-12 col-sm-6">
<label for="rentEndPicker">P?j?it do</label>
@(Html.Kendo().DatePickerFor(model => model.RentEndDate).Name("rentEndPicker").HtmlAttributes(new { style = "height:28px;", required = "required", validationmessage = "Vyberte datum" }))
</div>
Run Code Online (Sandbox Code Playgroud)
尝试使用Moment.js将日期选择器中的值转换为日期对象。这将解决你的问题。
就像是...
var startDate = moment($("#RentStartDate").data("kendoDateTimePicker").value());
Run Code Online (Sandbox Code Playgroud)
实际上,我建议几乎在任何时候操作日期时都使用 Moment.js,尤其是当这些日期来自网页元素时。Kendo 非常好,但我在尝试直接使用日期时遇到了问题。
| 归档时间: |
|
| 查看次数: |
674 次 |
| 最近记录: |