2017-02-24 62 views
0

我試圖以dd/mm/yyyy格式獲取當前的月份引導日期選擇器的開始日期和結束日期 例如當前本月在我的日曆是二月那麼我的價值觀會如何獲取當前月份的開始日期和結束日期datepicker dd/mm/yyyy

start date:1/02/2017 
and 
end date:28/02/2017 

的,如果我去了下個月是三月的同時,然後我的情況會

start date:1/03/2017 
and 
end date:31/03/2017 

我有輸出在控制檯中的價值但我得到的是這個

29/1/2017 
30/1/2017 
31/1/2017 
1/2/2017 
2/2/2017 

.... 
28/2/2017 
... 
11/3/2017 

這是在當前日期選擇器

這裏顯示日期的名單是我的代碼

var active_dates = ["1/2/2017", "5/2/2017"]; 
     $('#datepicker').datepicker({ 
      inline: true, 
      sideBySide: true, 
      todayHighlight: true, 
      format: 'dd/mm/yyyy', 
      beforeShowDay: function (date) { 
       var d = date; 
       var curr_date = d.getDate(); 
       var curr_month = d.getMonth() + 1; //Months are zero based 
       var curr_year = d.getFullYear(); 
       var formattedDate = curr_date + "/" + curr_month + "/" + curr_year 
       console.log(formattedDate); 
       if ($.inArray(formattedDate, active_dates) != -1) { 
        return { 
         classes: 'activeClass' 
        }; 
       } 
       return; 
      } 
     }); 

回答

0
I did fixed it with datejs 

This is alerting the first day: 

var fd = Date.today().clearTime().moveToFirstDayOfMonth(); 
var firstday = fd.toString("MM/dd/yyyy"); 
alert(firstday); 

This is for last day: 

var ld = Date.today().clearTime().moveToLastDayOfMonth(); 
var lastday = ld.toString("MM/dd/yyyy"); 
alert(lastday); 
+0

我想這個https://github.com/uxsolutions/自舉日期選擇器 –

相關問題