admin管理员组文章数量:1405393
I am trying to get the date which is 14th of January,2014 in Javascript but it is returning invalid date.
var clock;
$(document).ready(function () {
var currentDate = new Date();
var futureDate = new Date(currentDate.setFullYear(2014,17,1) + 1, 0, 1);
alert(futureDate);
});
Jsfiddle:/
I am trying to get the date which is 14th of January,2014 in Javascript but it is returning invalid date.
var clock;
$(document).ready(function () {
var currentDate = new Date();
var futureDate = new Date(currentDate.setFullYear(2014,17,1) + 1, 0, 1);
alert(futureDate);
});
Jsfiddle:http://jsfiddle/zJF35/
Share Improve this question edited Jan 6, 2014 at 18:40 Barmar 784k57 gold badges548 silver badges660 bronze badges asked Jan 6, 2014 at 18:39 Prithviraj MitraPrithviraj Mitra 11.9k15 gold badges63 silver badges107 bronze badges 4-
That's plain Javascript, not jQuery, except for the
$(document.ready()
part. – Barmar Commented Jan 6, 2014 at 18:40 - Your code does not match up with the JSFiddle example. Please change either. – Loyalar Commented Jan 6, 2014 at 18:41
-
setFullYear
only takes one argument, why are you giving it 3? – Barmar Commented Jan 6, 2014 at 18:41 - 1 The fiddle is fixed up here – Abraham Hamidi Commented Jan 6, 2014 at 18:41
4 Answers
Reset to default 4Try var futureDate = new Date(new Date().getFullYear(), 0, 14);
setFullYear() method sets the full year for a specified date according to local time.
dateObj.setFullYear(yearValue[, monthValue[, dayValue]])
here the middle one parameter is month value in which you are passing 17
which is not making sense and its converting into next year.
So You probably want this
var futureDate = new Date(currentDate.setFullYear(2014,0,14));
Js Fiddle Demo
You can try
var futureDate = new Date(2014,0,14);
Any future date in JavaScript (postman test uses JavaScript) can be retrieved as:
var dateNow = new Date();
var twoWeeksFutureDate = new Date(dateNow.setDate(dateNow.getDate() + 14)).toISOString();
//Note it returns 2 weeks future date from now.
本文标签: Get future date using JavascriptStack Overflow
版权声明:本文标题:Get future date using Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744286230a2598893.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论