2016-07-19 8 views
0

月と年だけを表示して選択する必要があるdatepickerを使用しています。そこで、dateFormatを 'MM yy'に変更しました。私が行うとき:今datepicker setDataは、dateFormat 'MM yy'に不正な日付を表示します。

$('.date-picker').datepicker('setDate', 'July 2016'); 

日付ピッカーは1月2022を示している。しかし、私はやるとき:

console.log($('.date-picker').datepicker("getDate")); 

それは00:00:00 GMT + 0800(PHT)

火2016年7月19日を示してい

dateFormatを 'MM dd yy'に、setDateを 'July 01 2016'に変更しようとしましたが、スムーズに動作します。 http://jsfiddle.net/gaddygs3/3/

ありがとう:ここ

はJSFiddleです!

答えて

0
$(document).ready(function() { 
$('#txtDate').datepicker({ 
changeMonth: true, 
changeYear: true, 
dateFormat: 'MM yy', 

onClose: function() { 
    var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
    var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
    $(this).datepicker('setDate', new Date(iYear, iMonth, 1)); 
}, 

beforeShow: function() { 
    if ((selDate = $(this).val()).length > 0) 
    { 
     iYear = selDate.substring(selDate.length - 4, selDate.length); 
     iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5), $(this).datepicker('option', 'monthNames')); 
     $(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1)); 
     $(this).datepicker('setDate', new Date(iYear, iMonth, 1)); 
    } 
} 
}); 
}); 

Check here

+0

を設定する形式を変更できますか?ありがとう:) – Wreigh

+0

Aaa ...申し訳ありませんが、私はそれが私を明確にすることはありませんでした。 – Ranjan

+0

私がしたいのは、コントローラからの初期日付を表示することです。だから私は現在の月と年をdatepickerに渡します。例えば7月と2016年、それから、私はdatepickerの日付を設定します。私は以前私の質問にこれを含めなかったことを申し訳ありません:| – Wreigh

-1

は、まず、私は右のランダムな一日を提供する必要があることが判明した日付

$('#checkin').datepicker('setDate',new Date('July 2016')); 
+0

申し訳ありませんが、わかりません:| | – Wreigh

関連する問題