本文介绍了提前日期+15天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个脚本... ----- < SCRIPT language =" JavaScript" type =" text / javascript"> <! - 函数makeArray(){ for(i = 0; i< makeArray.arguments.length; i ++) 这[i + 1] = makeArray.arguments [i]; } 函数makeArray0(){ for(i = 0; i< makeArray0.arguments.length; i ++) this [i] = makeArray0.arguments [i ]; } 函数y2k(数字){return(数字< 1000)?数字+ 1900:数字; } var months = new makeArray(''1月'','2月'',''3月'','4月''' ,''Ma y'',''June'',''July'',''August'',''September'',''October'','N ovember'',''December'' ); var days = new makeArray0(''星期日'',''星期一'',''星期二'',''星期三'''''星期四'',''星期五',''星期六'); var today = new Date(); var day = days [ today.getDay()]; var date = today.getDate()+ 15; var month = today.getMonth()+ 1; var year = y2k(today.getYear()); document.write(月[月] +'''+日期+'',''+年); // - > < / SCRIPT> --- 我需要这个脚本来将document.write推进15天,你可以看到 我尝试添加+ 15&qu ot; 在Var Date = today.getDate()之后工作,直到它开始 显示6月32天 今天。哈哈。 有人可以帮助我吗? Ro****@BeatToBeat.com 谢谢, Robert 解决方案 < script type =" text / javascript"> var today = new Date(); today.setDate(today.getDate()+ 15); document.write( ['''1月'',''2月'','三月'','四月'','五月','六月'','七月'', ''八月'','九月'',''十月'','十一月',''Decembe r''] [today.getMonth()] + " " + today.getDate()+ "," + today.getFullYear() ); < / script> ; 如果你发现自己经常使用它,创建一个Date.prototype Date.prototype.addDays = function(days){ this.setDate(this.getDate()+ days) //如果你愿意,可以使用修改后的日期对象。 } Mick Mick 对不起,但笑到你身边。 getDate()返回的值是 数,因此添加任何其他数字将给出正常算术 的补充。 < script type =" text / javascript"> var months = [ ''January'',''February'',''March' ','''四月'','五月'','六月','/ b $ b'''七月'','八月'','九月','十月' ',''十一月',''十二月'' ]; var days = [ ''星期天'',''周一'',''周二'',''周三'', ''周四'',''周五'',''周六'' ]; var today = new Date(); today.setDate(today.getDate()+ 15); document.write( days [today.getDay()] +'','' + today.getDate()+ '''' +月[today.getMonth()] +'','' + today.getF ullYear() ); < / script> - Rob I have a script...-----<SCRIPT language="JavaScript" type="text/javascript"><!--function makeArray() {for (i = 0; i<makeArray.arguments.length; i++)this[i + 1] = makeArray.arguments[i];} function makeArray0() {for (i = 0; i<makeArray0.arguments.length; i++)this[i] = makeArray0.arguments[i];} function y2k(number) { return (number < 1000) ? number + 1900 : number; } var months = newmakeArray(''January'',''February'',''March'',''April'',''Ma y'',''June'',''July'',''August'',''September'',''October'',''N ovember'',''December'');var days = newmakeArray0(''Sunday'',''Monday'',''Tuesday'',''Wednesday'' ,''Thursday'',''Friday'',''Saturday''); var today = new Date();var day = days[today.getDay()];var date = today.getDate( ) + 15;var month = today.getMonth() + 1;var year = y2k(today.getYear()); document.write(months[month] +'' '' + date + '', '' + year);//--></SCRIPT>--- I need this script to advance the document.write by 15 days, as you can seeI tried adding "+ 15"after the Var Date = today.getDate( ) that works fin until it startedshowing 32 days in Junetoday. LOL. Can anyone please assist me? Ro****@BeatToBeat.com Thank you,Robert 解决方案 The date constructor can take a number of milliseconds as an argumentto create a date object from. Perhaps this example will be of use: <script>var dt = new Date();var dt2 = new Date(dt.getTime()+15*24*60*60*1000);alert(dt+"\n"+dt2);</script> Refer to: http://msdn.microsoft.com/library/de...6jsobjdate.asp <script type="text/javascript">var today = new Date();today.setDate(today.getDate()+15);document.write([''January'',''February'',''March'',''April'',''May'',''June'', ''July'',''August'',''September'',''October'',''November'',''Decembe r''][today.getMonth()]+" "+today.getDate()+", "+today.getFullYear());</script> if you find yourself using it a lot, create a Date.prototype Date.prototype.addDays=function(days){this.setDate(this.getDate()+days)// do stuff with the revised date object if you want to.} Mick Mick Sorry, but the laugh''s on you. The value returned by getDate() is anumber, so adding any other number will give a normal arithmeticaddition.<script type="text/javascript"> var months = [''January'',''February'',''March'',''April'',''May'',''June'',''July'',''August'',''September'',''October'',''November'','' December'']; var days = [''Sunday'',''Monday'',''Tuesday'',''Wednesday'',''Thursday'',''Friday'',''Saturday'']; var today = new Date();today.setDate(today.getDate()+ 15); document.write(days[today.getDay()] + '', ''+ today.getDate() + '' ''+ months[today.getMonth()] + '', ''+ today.getFullYear());</script> --Rob 这篇关于提前日期+15天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-20 21:15