简体   繁体   中英

Change language to Bootstrap Datetimepicker

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?

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM