I still write program with Javascript, and I have problem how to calculate Date,which I want add month in Date.I want to explain like this. If I have date 05-22-2011, I want to add 9 month in my date.
To solve problem above, we can some way.First way is like this.
var currDate=new Date();
var currYear=currDate.getYear();
var currMonth=currDate.getMonth();
var currDate = currDate.getDate();
var monthAfterAdd;
var yearAfterAdd;
var newDateAfterAdd;
currMonth = currMonth + 9
monthAfterAdd = currMonth % 12
yearAfterAdd = currYear + ((currMonth - monthAfterAdd) / 12)
newDateAfterAdd = monthAfterAdd + "-" + currDate + "-" + yearAfterAdd
But for the simple program, we can write like this;
var ourDate=new Date();
ourDate.setDate.getMonth() + 9
Ok, this is simple lesson today.Correct me if wrong.
To solve problem above, we can some way.First way is like this.
var currDate=new Date();
var currYear=currDate.getYear();
var currMonth=currDate.getMonth();
var currDate = currDate.getDate();
var monthAfterAdd;
var yearAfterAdd;
var newDateAfterAdd;
currMonth = currMonth + 9
monthAfterAdd = currMonth % 12
yearAfterAdd = currYear + ((currMonth - monthAfterAdd) / 12)
newDateAfterAdd = monthAfterAdd + "-" + currDate + "-" + yearAfterAdd
But for the simple program, we can write like this;
var ourDate=new Date();
ourDate.setDate.getMonth() + 9
Ok, this is simple lesson today.Correct me if wrong.
No comments:
Post a Comment
Your Comment