0
從日期選擇日期選擇日期dd-mm-yy格式後,我需要下一年日期-1天day..ie來自:29-07- 2016再到:28-07-2016像這樣...請guyz幫助me..im分享我的源代碼從datepicker中選擇日期後,我希望明年的日期在下一個領域
$('#oldDate').on('change', function(e){
var oldDate = new Date(this.value);
$('.datepicker').datepicker({dateFormat:'dd-mm-yy'});
$('#old').html(new Date(oldDate));
oldDate.setDate(oldDate.getDate()-1);
oldDate.setFullYear(oldDate.getFullYear()+1);
\t var day = ("0" + oldDate.getDate()).slice(-2);
var month = ("0" + (oldDate.getMonth() + 1)).slice(-2);
var today = oldDate.getFullYear()+"-"+(month)+"-"+(day);
// var today = oldDate.(day)+"-"+(month)+"-"+getFullYear();
// alert(today);
$('#new').val(today);
<p class="left">
<label for="from">FROM:</label>
<input type="text" name="from" id="oldDate" class="datepicker"/>
</p>
<p class="pull-right">
<label for="to">TO:</label>
<input type="text" name="to" id="new">
</p>
它給予'NAN-AN-aN' – Drone
請檢查更新的代碼筆 - http://codepen.io/nagasai/pen/dXjVbJ,我今天看到的格式設置不同 –
請檢查更新後的codepen格式 - mm/dd/yyyy - http://codepen.io/nagasai/pen/Eypwxk –