我构建了一个滑块,您可以在其中选择数据并滑动滑块。 问题是,当我从日期选择器中选择“2013-02-01”并将滑块移动到凌晨 1 点时,我得到的是“2013-02-2”而不是“2013-02-02”。
这是我的代码:
$("#when").datepicker();
$("#open-till").slider({
range: "min",
value: 1230,
min: 1200,
max: 1860,
step: 30,
slide: slideTime
});
slideTime();
$("#SearchButton").click(function () {
SendData();
});
function slideTime(event, ui) {
var val0 = ui == undefined ? 1230 : ui.value,
minutes0 = parseInt(val0 % 60, 10),
hours0 = parseInt(val0 / 60 % 24, 10)
startTime = getTime(hours0, minutes0);
$("#time").text(startTime);
}
function getTime(hours, minutes) {
minutes = minutes == 0 ? '00' : minutes + "";
hours = hours + "";
if (hours.length == 1) {
hours = "0" + hours;
}
return hours + ":" + minutes;
}
function SendData() {
var WhenDateUnformatted = $('#when').val().split('/');
var startTimeSPLIT = startTime.split(':');
var parsedWhenDateUnformatted = parseInt(WhenDateUnformatted[1], 10);
if (startTimeSPLIT[0] < 20) {
WhenDateUnformatted[1] = (parsedWhenDateUnformatted + 1).toString();
}
var WhenDate = WhenDateUnformatted[2] + '-' + WhenDateUnformatted[0] + '-' + WhenDateUnformatted[1] + ' ' + startTime + ':00';
alert(WhenDate);
}
谢谢!