J'utilise le code suivant pour afficher uniquement les années:
$("#datepicker").datepicker( {viewMode: "years", minViewMode: "years"});
mais l'entrée apparaît au format "dd/mm/yyyy"
Comment puis-je résoudre ce problème car je n'ai pas le format "yyyy"
?
Essaye ça
$("#datepicker").datepicker({
format: "yyyy",
viewMode: "years",
minViewMode: "years"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<input type="text" id="datepicker" />
$("#datepicker").datepicker( {
format: " yyyy", // Notice the Extra space at the beginning
viewMode: "years",
minViewMode: "years"
});
Pour bootstrap datetimepicker
, attribuez la valeur decade
comme suit:
$(".years").datetimepicker({
format: "yyyy",
startView: 'decade',
minView: 'decade',
viewSelect: 'decade',
autoclose: true,
});
$("#year").datepicker( {
format: "yyyy",
viewMode: "years",
minViewMode: "years"
}).on('changeDate', function(e){
$(this).datepicker('hide');
});
Pour bootstrap 3 datepicker. (Notez les majuscules)
$("#datetimepicker").datetimepicker( {
format: "YYYY",
viewMode: "years"
});
format: "YYYY"
Devrait être un capital au lieu de "aaaa"
toujours l'année pour bootstrap 3 datetimepicker https://eonasdan.github.io/bootstrap-datetimepicker/
$('#year').datetimepicker({
format: 'YYYY',
viewMode: "years",
});
$("#year").on("dp.hide", function (e) {
$('#year').datetimepicker('destroy');
$('#year').datetimepicker({
format: 'YYYY',
viewMode: "years",
});
});