Tuesday, 17 December 2013

Get date of seventh day from today using javascript

Here, i posted the code below to get the date of seventh day from today using javascript.

Code:

 step:1
 var date = new Date();   //to get current day's date with GMT
//i.e, the variable date outputs as Tue Dec 17 2013 00:48:41 GMT+0530 (India Standard Time)

 step:2 
 date.setDate(date.getDate() + 7);
//Now the variable date holds the timestamp of the seventh'day from today i.e, 1387826522433

  step:3
 var dateMsg = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
alert(dateMsg); 
 //just checking with a alert , 
 alert(dateMsg); 
//Now variable  dateMsg outputs with format as 2013-12-24,

Finally ,we displayed the date of the seventh day from today using javascript.
 
 alert(dateMsg);


No comments:

Post a Comment