Javascript 如何更改日期范围选择器的日期格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32801013/
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
How to change the date range picker's date format?
提问by ayman
I am using this bootstrap date range picker. I want to change date format date to dd/MMM/yyyy
:
我正在使用这个引导日期范围选择器。我想将日期格式日期更改为dd/MMM/yyyy
:
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/latest/css/bootstrap.css" />
<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<script type="text/javascript">
$(function() {
$("#<%= txtName.ClientID %>").daterangepicker();
});
</script>
回答by Reisclef
If you want to present a different format, you need to add a locale object after you run the daterangepicker function. The site doesn't currently have a list of all the formats it supports, but try this:
如果要呈现不同的格式,则需要在运行 daterangepicker 函数后添加语言环境对象。该网站目前没有它支持的所有格式的列表,但试试这个:
$(function() {
$("#<%= txtName.ClientID %>").daterangepicker({
locale: {
format: 'DD/MMM/YYYY'
}
});
});
See here for more options: http://www.daterangepicker.com/#config
有关更多选项,请参见此处:http: //www.daterangepicker.com/#config
回答by Big Tree
There was actually a bug related to wrong dates being selected.
实际上存在与选择错误日期相关的错误。
Updating to the latest version resolved the locale format bug for me.
更新到最新版本为我解决了语言环境格式错误。