如何使用JavaScript将星期数添加到当前日期? [英] How to add number of weeks to the current date using JavaScript?

查看:57
本文介绍了如何使用JavaScript将星期数添加到当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查日期,一个是我选择的日期,第二个是当前日期+ 36周.

I need to run a check on dates, one being a selected date which I had, the second needs to be the current date + 36 weeks.

我环顾四周,我所看到的每个解决方案都需要GetDate() +天.

I've looked around and every solution I've seen involves GetDate() + days.

new Date().getDate() + 252

这不起作用,当前日期为2014/03/07,因此上面的行用7加上252,这是不正确的.

This is not working, the date currently is 2014/03/07 so the line above takes 7 and adds 252 which is not correct.

我正在寻找使用JavaScript或jQuery的任何解决方案.

I'm looking for any solution using JavaScript or jQuery.

谢谢.

推荐答案

检查 jsFiddle

JavaScript代码

check jsFiddle

JavaScript Code

var newdate = new Date();
newdate.setDate(newdate.getDate()+252);   // 36 week * 7 day = 252
alert(newdate.getFullYear() + "-" + (newdate.getMonth() + 1) + "-" + newdate.getDate());  // alert(newdate);

这篇关于如何使用JavaScript将星期数添加到当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆