問題已解決
打卡兩次,中午休息1個小時,用函數怎么計算?
溫馨提示:如果以上題目與您遇到的情況不符,可直接提問,隨時問隨時答
速問速答你可以使用以下函數來計算:
函數1:
function calculateHours(startTime, endTime, breakTime) {
let totalHours = 0;
let startTimeHour = startTime.getHours();
let endTimeHour = endTime.getHours();
let breakTimeHour = breakTime.getHours();
totalHours = endTimeHour - startTimeHour - breakTimeHour;
return totalHours;
}
函數2:
function calculateHours(startTime, endTime, breakTime) {
let totalHours = 0;
let startTimeMinutes = startTime.getMinutes();
let endTimeMinutes = endTime.getMinutes();
let breakTimeMinutes = breakTime.getMinutes();
totalHours = (endTimeMinutes - startTimeMinutes - breakTimeMinutes) / 60;
return totalHours;
}
2023 02/06 19:14
閱讀 546