本文介绍了使用'myDate - 1'减去日期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当我循环日期时,我违反任何规则 //确定阵亡将士纪念日 intFlag = 0; memDayHol = new Date(currentYear,4,31); while(intFlag == 0){ if(memDayHol.getDay()== 1){intFlag = 1;} else {memDayHol = memDayHol - 1;} } 我找不到可以使用的文档'+''运算符直接在日期 对象上,它假设加/减一天。这是否已被弃用 代码? TIA, Dan Am i breaking any rules when I loop dates like // Determine Memorial DayintFlag = 0;memDayHol = new Date (currentYear, 4, 31);while (intFlag == 0) {if (memDayHol.getDay() == 1) {intFlag =1;}else {memDayHol = memDayHol - 1;}} I can find no docs that one can use the ''+'' operator directly on a dateobject, and it assumes adding/subtracting a day(s). Is this deprecatedcode? TIA,Dan推荐答案 它有效吗? Is it working? 使用它似乎更安全: memDayHol.setDate(memDayHol.getDate() - 1); 但是整个算法都是无意义的。 如果你想要5月31日之前(或之前)的星期一日期,你可以计算出没有循环: memDayHol =新日期(currentYear,4,31); memDayHol.setDate(memDayHol.getDate() - memDayHol.getDay()+ 1); - It certainly seems safer to use:memDayHol.setDate(memDayHol.getDate()-1); but the whole algorithm is nonsense.If you want the date of the Monday before (or on) May 31, youcan calculate that without looping: memDayHol = new Date (currentYear, 4, 31);memDayHol.setDate(memDayHol.getDate()-memDayHol.getDay()+1);-- 它有效吗? Is it working? 是。 Yes. 这篇关于使用'myDate - 1'减去日期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 12:50