Reputation: 11812
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.net/zJF35/
Upvotes: 2
Views: 5737
Reputation: 342
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.
Upvotes: 0
Reputation: 40970
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));
Upvotes: 1
Reputation: 13789
Try var futureDate = new Date(new Date().getFullYear(), 0, 14);
Upvotes: 4