开发者

javascript date increment

开发者 https://www.devze.com 2022-12-28 09:35 出处:网络
I want to set a text bo开发者_运维知识库x with a date (in dd/mm/yyyy format)14 days ahead to current date in javascript . can any one help me regarding this ? This should do it:

I want to set a text bo开发者_运维知识库x with a date (in dd/mm/yyyy format) 14 days ahead to current date in javascript . can any one help me regarding this ?


This should do it:

var myDate=new Date();
myDate.setDate(myDate.getDate()+14);

then

document.getElementById(YOUR_TEXTBOX_ID).value = myDate.getDate() + "/" + 
  (myDate.getMonth() + 1) + "/" + myDate.getFullYear();


Date.js is a handy script for all kinds of JavaScript date manipulation. I've used it to make many date-based interfaces, including calendar controls.


Like Deodeus suggested, use Date.js:

var myDate = Date.today().add(14).days();
document.getElementById('mytextbox').value = myDate.toString('dd/MM/yyyy');


Following is the function to increment date by one day in javascript.

function IncrementDate(date) {         
     var tempDate = new Date(date);
        tempDate.setDate(tempDate.getDate() + 1);
        return tempDate;
} 

Function calling...

var currentDate = new Date();
var IncrementedDate =  IncrementDate(currentDate);
0

精彩评论

暂无评论...
验证码 换一张
取 消