大家好,并提前感谢您的帮助。我在将Javascript日期代码从当前日期提前到明天的日期时遇到问题。我在之前的帖子中搜索过,但答案似乎没有起作用。
<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())) ;
</script>
为了明天的约会日期,+ 1
会在哪里插入?
答案 0 :(得分:1)
now.setDate(now.getDate() + daysToAdd);
应该做的伎俩。它甚至不是jQuery,只是Javascript。如果您将1添加到字符串的末尾,请确保现在仍被视为日期,并且尚未在某处重新分配给其他类型。
daysToAdd是文字还是变量都不重要。两者都应该有用。
更具体地说,这应该有效:
<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())) ;
</script>