twitter-bootstrap 将语言更改为 Bootstrap Datetimepicker
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34271030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change language to Bootstrap Datetimepicker
提问by Sredny M Casanova
I'm using the datetimepickerof 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:
我正在使用Bootstrap的日期时间选择器,它运行良好。问题是它是英文的,我需要西班牙文,我读过一些帖子,但对我没有任何作用。我的 HTML 定义为:
<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:
在 javascript 中,我只有一个与 datetimepicker 相关的函数,这是:
$('.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.jsbut can I add the definition of days and months inside my javascript?
那么,我应该添加什么来将其更改为西班牙语?我读过这是使用locale.js但我可以在我的 javascript 中添加天和月的定义吗?
回答by Shehary
You need to add locale, reference can be found here
您需要添加语言环境,参考可以在这里找到
For spanish locale: 'es'
西班牙语 locale: 'es'
Script
脚本
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/es.js"></script>
DateTimePicker in Spanish
西班牙语中的 DateTimePicker
$(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>

