twitter-bootstrap Bootstrap 日期选择器显示月份名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24861246/
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
Bootstrap date picker display month name
提问by Akash
I'm using Bootstrap date picker and I want to display the month in the date picker field. See below image.
我正在使用 Bootstrap 日期选择器,我想在日期选择器字段中显示月份。见下图。


I tried following code:
我尝试了以下代码:
$('#example1, #example2, #example3').datepicker({
format: "dd/MM/yyyy"
});
But it is no use. Any one can help me?
但它没有用。任何人都可以帮助我吗?
Edit:I want to display the month name (14 August 2014) in the text field instead of the date that are displayed now - 14/08/2014.
编辑:我想在文本字段中显示月份名称(2014 年 8 月 14 日),而不是现在显示的日期 - 14/08/2014。
回答by onegina alyona
You can do
你可以做
$('#input_date').datepicker({
format: 'dd M yyyy'
});
回答by Arzon Barua
I hope you will get your desire output from the following code
我希望你能从下面的代码中得到你想要的输出
$('#example1,#example2,#example3').datepicker({
format: "dd MM yyyy",
});
but I would like to recommend you to use class rather using multiple IDs for multiple fields. For example suppose use class name example1 for all fields then the code will be something like this
但我想建议您使用类而不是为多个字段使用多个 ID。例如假设对所有字段使用类名 example1 那么代码将是这样的
$('.example1').datepicker({
format: "dd MM yyyy",
});
回答by Akram
momentjsis responsible for formatting the date.
momentjs负责格式化日期。
MM - 01 02 ... 11 12
MM - 01 02 ... 11 12
MMM - Jan Feb ... Nov Dec
MMM - 1 月 2 月 ... 11 月 12 月
MMMM - January February ... November December
MMMM - 一月 二月 ... 十一月 十二月
The following code format the month name in the text field
以下代码格式化文本字段中的月份名称
$('#example1, #example2, #example3').datepicker({
format: "dd MMMM yyyy"
});
回答by nexttus
This should work
这应该工作
$('#example1').datetimepicker({format:'D-MMM-YYYY'});
回答by ArthNRick
use dd/mm/yyyy (MM display month name, mm numeric)
使用 dd/mm/yyyy (MM 显示月份名称,mm 数字)
format String. Default: “mm/dd/yyyy”
格式字符串。默认值:“mm/dd/yyyy”
The date format, combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy.
日期格式,d、dd、D、DD、m、mm、M、MM、yy、yyyy的组合。
d, dd: Numeric date, no leading zero and leading zero, respectively. Eg, 5, 05. D, DD: Abbreviated and full weekday names, respectively. Eg, Mon, Monday. m, mm: Numeric month, no leading zero and leading zero, respectively. Eg, 7, 07. M, MM: Abbreviated and full month names, respectively. Eg, Jan, January yy, yyyy: 2- and 4-digit years, respectively. Eg, 12, 2012.
d、dd:数字日期,分别为无前导零和前导零。例如,5、05。D、DD:分别是工作日的缩写名称和完整的工作日名称。例如,星期一,星期一。m、mm:数字月份,分别无前导零和前导零。例如,7、07。M、MM:分别是缩写和完整的月份名称。例如,Jan、January yy、yyyy:分别是 2 位数和 4 位数年份。例如,2012 年 12 月。
回答by Richard Socker
I think that the only way is to implement the hide()event and change the text field:
我认为唯一的方法是实现hide()事件并更改文本字段:
months = [ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ];
$('#datePickerID').datepicker()
.on("hide", function(e) {
var temp=e.delegateTarget.firstElementChild.value.split('/');
var selectedMonthName = months[parseInt(temp[1])-1];
e.delegateTarget.firstElementChild.value=temp[0]+' '+selectedMonthName+' '+temp[2];
});
回答by Confused
Edit
编辑
Try separate initialization
尝试单独初始化
$('#example1').datepicker({
format: "dd/MM/yyyy"
});
$('#example2').datepicker({
format: "dd/MM/yyyy"
});
$('#example3').datepicker({
format: "dd/MM/yyyy"
});
OR
或者
Give all of them a single class "example" then use
给他们所有人一个单一的类“例子”然后使用
$('.example').datepicker({
format: "dd/MM/yyyy"
});
Check documentation http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format;
检查文档 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format;

