简体   繁体   English

如何计算javascript中日期的第5个日期

[英]how to calculate the 5th date from a date in javascript

I have a date in a javascript variable 我在javascript变量中有一个日期

var cDate='07/21/2012'  `(mm/dd/YYY format)`

I need to find out the 5th day from the date in cDate Variable 我需要找出cDate Variable日期的第5天

ie newDate= '07/26/2012' 即newDate = '07/26/2012' 26/2012 '07/26/2012'

suppose if the cDate='07/28/2012' then newDate='08/2/2012' But I did know how. 假设cDate='07/28/2012' then newDate='08/2/2012'但我确实知道如何。 I have tried a lot and searched but my result is wrong. 我已经尝试了很多并搜索,但我的结果是错误的。

Please replay 请重播

thanks in advance 提前致谢

myDate = new Date(2012, 07, 28)
new Date(myDate.getTime() + 5*24*60*60*1000);

OR extend the Date Class as 或者将日期类扩展为

Date.prototype.addDays = function(days) {
    this.setDate(this.getDate() + days);
    return this;
};

Or you can even use this library. 或者你甚至可以使用这个库。 http://www.datejs.com/ http://www.datejs.com/

Have you tried the following? 你试过以下吗?

cDate = new Date(2012, 07, 28)
cDate.setDate(cDate.getDate() + 5);

please try this 请试试这个

var myDate=new Date();
myDate.setDate(myDate.getDate()+5);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM