Change language to Bootstrap Datetimepicker

20,380

You need to add locale, reference can be found here

For spanish locale: 'es'

Script

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/es.js"></script>

DateTimePicker in Spanish

$(document).ready(function(){
	$('.input-group.date').datetimepicker({
		locale: 'es',
	});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/es.js"></script>
<br>
<div class="form-group">
     <div class='input-group date datepicker' name="datepicker" >
          <input type='text' class="form-control placementT" id="fecha">
             <span class="input-group-addon">
                   <span class="glyphicon glyphicon-calendar">
                   </span>
            </span>
      </div>
</div>
Share:
20,380
Sredny M Casanova
Author by

Sredny M Casanova

Student of Informatic Engineering at UNET (Universidad Nacional Experimental del Táchira)

Updated on May 17, 2020

Comments

  • Sredny M Casanova
    Sredny M Casanova about 4 years

    I'm using the datetimepicker of Bootstrap, it's working pretty well. The thing is that it's in english, and I need it in spanish, I had read some post but nothing works to me. my HTML is defined as:

    <div class="form-group">
      <div class='input-group date datepicker' data-date-startdate="{{$student->middle}}" name="datepicker" >
        <input type='text' class="form-control placementT" id="fecha">
        <span class="input-group-addon">
          <span class="glyphicon glyphicon-calendar"></span>
        </span>
      </div>
    </div>
    

    In the javascript, I have only one function related with the datetimepicker, this is:

    $('.input-group.date').each(function() {
      $(this).datetimepicker().on('dp.hide',function (ev) {
        //something
      });
    });
    

    So, what should I add to change this to spanish?I had read that this is with locale.js but can I add the definition of days and months inside my javascript?