我们的工作周从星期三开始,到星期二结束,所以我希望动态地允许用户从周三列表中选择(在php和/或js中轻松完成),并将该日期作为开始本周他们正在编辑或准备提交。
我的尝试mod:
window.onload = lastdateInit;
function lastdateInit(){
var startOfWeek = moment().startOf('isoweek').add(2,'days').toDate();
console.log(startOfWeek);
var tue = moment(startOfWeek).add(5,'days').toDate();
var wed = moment(startOfWeek).add(6,'days').toDate();
var thu = moment(startOfWeek).add(1,'days').toDate();
var fri = moment(startOfWeek).add(2,'days').toDate();
var sat = moment(startOfWeek).add(3,'days').toDate();
var endOfWeek = moment().endOf('isoweek').add(7,'days').toDate();
var monDay =moment(startOfWeek).format("MM/DD/YYYY");
var tueDay =moment(tue).format("MM/DD/YYYY");
var wedDay =moment(wed).format("MM/DD/YYYY");
var thuDay =moment(thu).format("MM/DD/YYYY");
var friDay =moment(fri).format("MM/DD/YYYY");
var satDay =moment(sat).format("MM/DD/YYYY");
var sunDay =moment(endOfWeek).format("MM/DD/YYYY");
document.getElementById("day6").innerHTML = monDay;
document.getElementById("day7").innerHTML = tueDay;
document.getElementById("day1").innerHTML = wedDay;
document.getElementById("day2").innerHTML = thuDay;
document.getElementById("day3").innerHTML = friDay;
document.getElementById("day4").innerHTML = satDay;
document.getElementById("day5").innerHTML = sunDay;
document.getElementById("datepicker").value = wedDay;
}
我对jQuery和moment.js依赖关系很好,就像我读过的那样,moment.js 它用于时间操作,但我可以&#39似乎没有把东西包裹起来,所以星期一的星期日也没有 星期一至星期二。
基本上,它正是我所需要的,但抵消了2天。这让它听起来很简单(我确定它是这样),但我在js上非常绿色,并且正在寻求指导。
提前感谢任何回复。
仪射线
答案 0 :(得分:0)
你走了: 这个想法是你在“周开始”中增加2天,并从那里正常工作。
window.onload = lastdateInit;
function lastdateInit(){
var startOfWeek = moment().startOf('isoweek').add(2, 'days').toDate();
var thu = moment(startOfWeek).add(1,'days').toDate();
var fri = moment(startOfWeek).add(2,'days').toDate();
var sat = moment(startOfWeek).add(3,'days').toDate();
var sun = moment(startOfWeek).add(4,'days').toDate();
var mon = moment(startOfWeek).add(5,'days').toDate();
var tue = moment(startOfWeek).add(6,'days').toDate();
var wedDay =moment(startOfWeek).format("MM/DD/YYYY");
var thuDay =moment(thu).format("MM/DD/YYYY");
var friDay =moment(fri).format("MM/DD/YYYY");
var satDay =moment(sat).format("MM/DD/YYYY");
var sunDay =moment(sun).format("MM/DD/YYYY");
var monDay =moment(mon).format("MM/DD/YYYY");
var tueDay =moment(tue).format("MM/DD/YYYY");
document.getElementById("day1").innerHTML = wedDay;
document.getElementById("day2").innerHTML = thuDay;
document.getElementById("day3").innerHTML = friDay;
document.getElementById("day4").innerHTML = satDay;
document.getElementById("day5").innerHTML = sunDay;
document.getElementById("day6").innerHTML = monDay;
document.getElementById("day7").innerHTML = tueDay;
document.getElementById("datepicker").value = tueDay;
}