已编辑
$(function() {
$('input[name="Date2"]').daterangepicker({
minDate: getCurrentDateToday() + " 8:30 AM",
dateLimit: {
"days": 1
},
timePicker: true,
timePickerIncrement: 1,
locale: {
format: 'MM/DD/YYYY h:mm A'
}
},
function(start, end, label) {
var breakStart = "12:00 PM" , breakEnd = "12:30 PM";
var start_end_diff = (new Date(end) - new Date(start)) / 1000 / 60;
var break_diff = exclude_BreakTiming(start,end ,breakStart, breakEnd);
var total_minutes = (start_end_diff - break_diff);
$('#txtTotalHrs').val(getTimeFromMins(total_minutes));
});
});
function getTimeFromMins(mins) {
// do not include the first validation check if you want, for example,
// getTimeFromMins(1530) to equal getTimeFromMins(90) (i.e. mins rollover)
if (mins >= 24 * 60 || mins < 0) {
throw new RangeError("Valid input should be greater than or equal to 0 and less than 1440.");
}
var h = mins / 60 | 0,
m = mins % 60 | 0;
return moment.utc().hours(h).minutes(m).format("hh:mm");
}
function getCurrentDateToday() {
var currentDate = new Date();
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
var fullDate = month + "/" + day + "/" + year;
return fullDate;
}
function exclude_BreakTiming (StartTime , EndTime, BreakStart, BreakEnd){
StartTime = Date.parse('01/01/2011 ' +StartTime.format('h:mm A'));
EndTime = Date.parse('01/01/2011 ' +EndTime.format('h:mm A'));
var breakStart = Date.parse('01/01/2011 '+BreakStart);
var breakEnd = Date.parse('01/01/2011 '+BreakEnd);
if((StartTime <= breakEnd) || ((StartTime < breakStart) && (EndTime > breakEnd)))
{
return ((breakEnd - breakStart) /1000 /60);
}else{
return 0;
}
}