Change language datetimepicker jquery

1

I would like to be able to change the language of the datetimepicker and there is no way to do it, I have seen some examples and it does not change anything.

function datepicker(){ 
  $(".datepicker").datetimepicker({
    format: "d-m-Y",
    language: 'es',
  });
}
    
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/jquery.datetimepicker.full.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.min.css" rel="stylesheet"/>

<div class="col-md-2">
  <input type="text"
         id="idFechaAltaConv"
         class="form-control input-sm datepicker " />
</div>
    
asked by Lorenzo Martín 05.04.2018 в 11:20
source

1 answer

2

The problem lies in the documentation you have seen. Surely it was another plugin. According to the plugin official you are using link , just use $.datetimepicker.setLocale('es');

$(function(){
  $(".datepicker").datetimepicker({
    format: "d-m-Y"
  });
  $.datetimepicker.setLocale('es');
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/jquery.datetimepicker.full.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.min.css" rel="stylesheet"/>

<div class="col-md-2">
  <input type="text"
         id="idFechaAltaConv"
         class="form-control input-sm datepicker " />
</div>

NOTE: In this case we are starting the plugin once the page has loaded using $(function(){..}) to wait for loading Jquery. But we could put this functionality in any other function and call it when we need it.

function aplicarDatetimepicker(selector, formato, codigoIdioma) {
    $(selector).datetimepicker({
        format: formato
    });
    $.datetimepicker.setLocale(codigoIdioma);
}
    
answered by 05.04.2018 / 11:41
source