Adding Day to Date to Make Current Date Tomorrow - Javascript
本问题已经有最佳答案,请猛点这里访问。
大家好,并提前感谢您的帮助。 我在将Javascript日期代码从当前日期提前到明天的日期时遇到问题。 我在以前的帖子中搜索了这些,但答案似乎没有起作用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <SCRIPT LANGUAGE="JavaScript"> // Get today's current date. var now = new Date(); // Array list of days. var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); // Array list of months. var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December'); // Calculate the number of the current day in the week. var date = ((now.getDate()<10) ?"0" :"")+ now.getDate(); // Calculate four digit year. function fourdigits(number) { return (number < 1000) ? number + 1900 : number; } // Join it all together today = days[now.getDay()] +"," + months[now.getMonth()] +"" + date +"," + (fourdigits(now.getYear())) ; |
为了明天的约会日期,
1 | now.setDate(now.getDate() + daysToAdd); |
应该做的伎俩。 它甚至不是jQuery,只是Javascript。 如果您将1添加到字符串的末尾,请确保现在仍被视为日期,并且尚未在某处重新分配给其他类型。
daysToAdd是文字还是变量也无关紧要。 两者都应该有效。
更具体地说,这应该工作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <SCRIPT LANGUAGE="JavaScript"> // Get today's current date. var now = new Date(); now.setDate(now.getDate() + 1); // Array list of days. var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); // Array list of months. var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December'); // Calculate the number of the current day in the week. var date = ((now.getDate()<10) ?"0" :"")+ now.getDate(); // Calculate four digit year. function fourdigits(number) { return (number < 1000) ? number + 1900 : number; } // Join it all together today = days[now.getDay()] +"," + months[now.getMonth()] +"" + date +"," + (fourdigits(now.getYear())) ; |