Change language to Bootstrap Datetimepicker

僤鯓⒐⒋嵵緔 提交于 2019-12-10 13:54:35

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/34271030/change-language-to-bootstrap-datetimepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!