开发者

DateTime that adds the specified number of months to the value

Here is my problem.

in c# i can do this using this:

DateTime.Now.AddMonths(12);

But i don't know how 开发者_如何转开发to do it in JavaScript/jQuery, any ideas ? i'm trying google it, but i only found Converts .... (any tip in how i can search this, will help me too)

Thanks in advance.

PS: I Found this: A couple of classes featuring the same utilities that .NET classes do. , but, can i only achieve this with one "plugin" ?


You can probably just create Date object and calculate the appropriate seconds to add on. But to make life easier, why not use something like this: http://www.datejs.com to do the heavy lifting for you?


var date = new Date();
date.setMonth(date.getMonth() + 12);

Obviously 12 is a bit of a silly example, since it's a whole year...

Oh, and if your new month doesn't have enough days for the old day of month, that then wraps around too, so you have to be careful. For instance:

var date = new Date();
var day = date.getDate();
date.setMonth(date.getMonth() + 1);
if (date.getDate() != day) // day too big, month rolled over
  date.setDate(0); // Use last day of the month


var date = new Date(); var date6MonthsFromNow = new Date(date.getTime() + (182*24*60*60*1000));

the formula is simply [current time in mils + (#days in 6 months * #hrs in day * #mins in hrs * #sec in min * #mils in sec)]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜