将字符串转换为日期,添加一天,然后作为查询字符串的一部分发布

时间:2015-02-02 13:00:44

标签: javascript

我有一个< p>目前持有2015-02-02(今日)。我想取这个字符串,在日期中添加一个,然后将其作为查询字符串的一部分发布到RPG程序(URL的一部分)。使用我当前的代码,什么都没发生?

 <p id="result"><%= (Today) %></p>
 <input name="Submit" type="submit" value="Next Day" onClick="nextDay()">

javascipt的

 function nextDay(){

    var currDate = document.getElementById('results').innerHTML ;
    var dt = new Date(currDate);
    dt = dt.setDate( gt.getDate + 1 )
    var newDate= = dt.toString();

    url = 'http://bvr:7018/CLPOOREa.rpgle?CurrDate=' + newDate; 
    window.location.href = url; 
}

2 个答案:

答案 0 :(得分:0)

function nextDay(){

    var currDate = document.getElementById('results').innerHTML ;
    var tomorrow = new Date(currDate);
    tomorrow = tomorrow.setDate(tomorrow.getDate() + 1);

    url = 'http://bvr:7018/CLPOOREa.rpgle?CurrDate=' + tomorrow; 
    window.location.href = url; 
}

这可能适合你。

答案 1 :(得分:0)

setDate()不返回日期,它设置该Date实例的日期。如上所述,请查看Moment.js。但这也应该有所帮助:

var today = new Date();
console.log('Today is : ' + today);
var tomorrowDay = today.getDate() + 1;
console.log('Tomorrow\'s day number is: ' + tomorrowDay);
today.setDate(tomorrowDay);
console.log('Tomorrow is: ' + today.toString());

//output
"Today is : Mon Feb 02 2015 08:18:06 GMT-0500 (Eastern Standard Time)" 
"Tomorrow's day number is: 3"
"Tomorrow is: Tue Feb 03 2015 08:18:06 GMT-0500 (Eastern Standard Time)"