下面的代碼是我最終想要結束的,但我不認爲這就是momentjs的工作原理。如何檢查當前時間是否在特定工作時間之間?
let time = moment()
let dayOfWeek = time.weekday()
let hour = time.hour()
let minutes = time.minutes()
let isBusinessHours = false
// Sunday=1, Monday=2, etc..
// Mon-Thu - 8:30am to 7:30pm
if (dayOfWeek >= 2 && dayOfWeek <= 5) {
if ((hour >= 8 && hour <= 19) && (minutes >= 0 && minutes <= 30)) {
isBusinessHours = true
}
} else if (dayOfWeek == 6) { // Fri - 8:30am - 5:30pm
} else if (dayOfWeek == 7) { // Sat - 10:30am - 4:00pm
}
這似乎是一個解決的問題,但我似乎無法破解它。
非常明確的例子。 +1 –
有一個名爲'isBetween'的函數,所以你也可以使用'currentTime.isBetween(opening,closing)'' –