我正在使用kendo DateTimepicker。我有一个开始和结束日期。当我选择开始日期时,我希望生成结束日期比开始日期多30分钟。例如,如果选择的开始日期是5/11/2016 2.30PM我希望结束日期是5/11/2016 3.00PM ..任何人都可以帮助我。
由于
剑道代码:
<tr>
<td>
<div>
<label for="start_date" >Start Date</label>
</div>
<div data-container-for="data.start_date" onchange="startDate()">
<input data-role="datepicker" data-bind="value: data.start_date" id="startDate"/>
<input data-role="timepicker" data-bind="value: data.start_date" id="startTime"/>
</div>
</td>
<td>
<div>
<label for="end_date">End Date</label>
</div>
<div data-container-for="data.end_date">
<input data-role="datepicker" data-bind="value: data.end_date" id="endDate" />
<input data-role="timepicker" data-bind="value: data.end_date" id="endTime"/>
</div>
</td>
</tr>
Function:
function startDate() {
var startDate = kendo.toString($("#startDate").data("kendoDatePicker").value(), 'MM/dd/yyyy');
var startTime = kendo.toString($("#startTime").data("kendoTimePicker").value(), 'hh:mm tt')
var endtDate = kendo.toString($("#endDate").data("kendoDatePicker").value(), 'MM/dd/yyyy');
var endTime = kendo.toString($("#endTime").data("kendoTimePicker").value(), 'hh:mm tt')
var StartDate = new Date($("#startDate").val());
var futureDateTime = new Date(StartDate.setMinutes(StartDate.getMinutes() + 30));
var End = $("#endDate").data("kendoDatePicker").value(futureDateTime);
var EndTime = $("#endTime").data("kendoTimePicker").value(futureDateTime);
}
答案 0 :(得分:1)
请尝试使用以下代码段。点击按钮,您可以获得两个日期时间选择器的单独日期和时间。
<div>
<input id="startDate" />
<input id="endDate" />
<button onclick="GetDateAndTime();">Get date an time separatly</button>
<script>
function GetDateAndTime() {
var startDate = kendo.toString($("#startDate").data("kendoDateTimePicker").value(), 'MM/dd/yyyy');
var startTime = kendo.toString($("#startDate").data("kendoDateTimePicker").value(), 'hh:mm tt')
var endtDate = kendo.toString($("#endDate").data("kendoDateTimePicker").value(), 'MM/dd/yyyy');
var endTime = kendo.toString($("#endDate").data("kendoDateTimePicker").value(), 'hh:mm tt')
alert(startDate);
alert(startTime);
alert(endtDate);
alert(endTime);
}
$(document).ready(function () {
var tempDate = new Date();
$("#startDate").kendoDateTimePicker({
value: tempDate,
change: onchange
});
$("#endDate").kendoDateTimePicker({
value: tempDate,
});
$("#startDate").data("kendoDateTimePicker").trigger("change");
function onchange() {
var startDate = new Date($("#startDate").val());
var newDateTime = new Date(startDate.setMinutes(startDate.getMinutes() + 30));
$("#endDate").data("kendoDateTimePicker").value(newDateTime);
}
});
</script>
</div>
如果有任何疑虑,请告诉我。
答案 1 :(得分:0)
参考这个。您粘贴的页面仍然不是我想要的。
<!DOCTYPE html>
<html>
<head>
<base href="http://demos.telerik.com/kendo-ui/datepicker/index">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.504/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.2.504/styles/kendo.material.min.css" />
<script src="//kendo.cdn.telerik.com/2016.2.504/js/jquery.min.js"></script>
<script src="//kendo.cdn.telerik.com/2016.2.504/js/kendo.all.min.js"></script>
</head>
<body>
<div id="example">
<div class="demo-section k-content">
<h4>Start Date:</h4>
<input id="startDate" value="10/10/2011" style="width: 100%" />
<h4>End Date:</h4>
<input id="endDate" value="10/10/2011" style="width: 100%" />
</p>
</div>
<script>
$(document).ready(function() {
// current date
var currentDate = new Date();
// create DatePicker from input HTML element
$("#startDate").kendoDateTimePicker({
value: currentDate,
change: onStartDateChange
});
// Set new datetime 30 minutes ahead
var futureDateTime = new Date(currentDate.setMinutes(currentDate.getMinutes() + 30));
$("#endDate").kendoDateTimePicker({
// display month and year in the input
value: futureDateTime,
});
function onStartDateChange() {
//console.log("Change event :: " + kendo.toString(this.value()));
// Get start date
var startDate = new Date($("#startDate").val());
//console.log("Start date :: " + kendo.toString(startDate));
// Add 30 minutes
var futureDateTime = new Date(startDate.setMinutes(startDate.getMinutes() + 30));
//console.log("Future date :: " + kendo.toString(futureDateTime));
// Set time 30 minutes from now
$("#endDate").data("kendoDateTimePicker").value(futureDateTime);
}
});
</script>
</div>
</body>
</html>