我需要显示提醒时间前一小时和提醒时间后一小时的时间。假设我的提醒时间是上午11点,提醒需要从上午10点开始显示,下午12点结束。现在它放映了一整天。reminder_date是我的提醒时间
var countDownDate = new Date($('#end_time').val()).getTime();
var countStartDate = new Date($('#start_time').val()).getTime();
var now = new Date().getTime();
var dsr = <?=$todo['dsr']?>;
if(dsr.length> 0){
let dsr_str ='<ul>';
$.each(dsr, function(index, item){
let now = new moment(item['reminder_date']);
var start_distance = countStartDate - now;
if(start_distance < 0){
var distance = countDownDate - now;
dsr_str += '<li>'+item['company']+' | '+item['phone']+' | <b>'+now.format("hh:mm A")+'</b></li>';});
dsr_str +='</ul>'
$(document).Toasts('create', {
title: 'DSR Reminder',
class: 'bg-success',
body: dsr_str
})
}
if (distance < 0) {
clearInterval(x);
location.reload(true);
}
}
}, 1000);
});发布于 2020-12-20 14:35:33
只需从countDownDate /countStartDate中加/减3600000 (60分钟*60秒* 1000毫秒),这只是毫秒数
var countDownDate = new Date($('#end_time').val()).getTime();
var countStartDate = new Date($('#start_time').val()).getTime();
countDownDate+=3600000;
countStartDate-=3600000;或者使用start_distance < 3600000
,它将检查当前时间是否小于开始日期前一个小时。
https://stackoverflow.com/questions/65377462
复制相似问题