2017-08-21 1 views
-1

Ceci est mon code html:Comment afficher le mois précédent uniquement dans mon agenda?

<div class="input-group input-medium date date-picker" 
    data-date="" 
    data-date-format="yyyy-mm-dd" 
    data-date-viewmode="years" 
    data-date-minviewmode="months" 
    data-date-end-date="+0d"> 
    <input name="water.month" type="text" value="${water?.month}" class="form-control" id="months"> 
    <span class="input-group-btn"> 
     <button class="btn btn-info" type="button"><i class="fa fa-calendar"></i></button> 
    </span> 
</div> 

Je veux montrer que le mois précédent dans mon calendrier. Comment puis-je le faire?

+2

Quel plugin datepicker utilisez-vous? – BenM

+0

bootstrap datepicker –

+0

RTM: ['startDate'] (https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#senddate) et [' endDate'] (https: //bootstrap-datepicker.readthedocs .io/fr/latest/options.html # startdate). – BenM

Répondre

1

Si je comprends bien votre question, vous voulez afficher seulement un mois (mois précédent). Si oui, essayez ceci:

<div id='myDate'> 
    <input type="text" type="text" class="form-control"/> 
</div> 

Javascript:

var now = new Date(); 
var prevMonthFirstDate = new Date(now.getFullYear() - (now.getMonth() > 0 ? 0 : 1), (now.getMonth() - 1 + 12) % 12, 1); 
var prevMonthLastDate = new Date(now.getFullYear(), now.getMonth(), 0); 
$('#myDate input').datepicker({ 
startDate: prevMonthFirstDate, 
endDate: prevMonthLastDate 
}); 

Pour comprendre comment obtenir le premier jour du mois, jetez un oeil à this answer

Voici une JSFiddle