我正在尝试用时间减法的值填充数组/列表。我有这种格式“09.00 AM”的开始时间和相同格式的结束时间,例如:“06.00 PM”,这两个时间都来自两个下拉菜单(值从上午 9 点到晚上 9 点,每小时增量)实际上是 jquery 时间选择器控件。这就是我想要做的..在用户选择两个时间之后,我想用位于两个选定时间值之间的单个“小时”标记值填充一个数组/列表。例如:选择上午 9 点和下午 12 点应该给我值 {“10.00 AM”、“11.00 AM”}.. 选择 10 AM 到 4 PM 应该给我 {“11.00 AM”、“12.00 PM”、“01.00 PM” , "02:00 PM", "03:00 PM"}..
var FirstTime = container.find('#1time').val();
var SecondTime = container.find('#2time').val();
var busyTimes = [];
busyTimes = getBusyTimes(FirstTime , SecondTime);
函数js:
function getBusyTimes(first, second) {
var f = first.split(' '), s = second.split(' ');
if (first == '12.00 AM') f[0] = '0';
if (first == '12.00 PM') f[1] = 'AM';
if (second == '12.00 AM') s[0] = '24';
if (second == '12.00 PM') s[1] = 'AM';
f[0] = parseInt(f[0], 10) + (f[1] == 'PM' ? 12 : 0);
s[0] = parseInt(s[0], 10) + (s[1] == 'PM' ? 12 : 0);
int i = s[0] - f[0];
// I have difference in hours in "i"
//From here, I want to make use of value 'i' -- calculate in between
// hourly values and return the array back to
// original function above.
}