twitter-bootstrap 在选择时更改引导日期选择器日期格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19992727/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 19:12:31  来源:igfitidea点击:

Change bootstrap datepicker date format on select

twitter-bootstrapdatepicker

提问by Luke Villanueva

I'm using bootstrap datepicker on a textbox. The default format of the date when you select a date is mm/dd/yyyy. Now I want to change it to dd/mm/yyyy. How can I accomplish this. Right now I'm just initializing it just like this.

我在文本框上使用引导日期选择器。选择日期时日期的默认格式为 mm/dd/yyyy。现在我想把它改成 dd/mm/yyyy。我怎样才能做到这一点。现在我只是像这样初始化它。

$('.datepicker').datepicker()

What should I add to change its format?

我应该添加什么来更改其格式?

回答by unlimit

See http://www.eyecon.ro/bootstrap-datepicker/

http://www.eyecon.ro/bootstrap-datepicker/

 $('.datepicker').datepicker({
    format: 'dd/mm/yyyy'
 });

回答by MiniGunnR

As of 2016 I used datetimepicker like this:

截至 2016 年,我使用了这样的 datetimepicker:

$(function () {
    $('#date_box').datetimepicker({
        format: 'YYYY-MM-DD hh:mm'
    });
});

回答by Web_Developer

I am using Bootstrap v3.3.4 and using the code:

我正在使用 Bootstrap v3.3.4 并使用代码:

 $('.datepicker').datepicker({
    dateFormat: 'dd-mm-yy'
 });

Output is: 16-07-2015

输出为:16-07-2015

Note: only need "yy" for full year.

注意:全年只需要“yy”。

回答by Bhumika Vaza

If by ID:

如果通过 ID:

$('#datepicker').datepicker({
    format: 'dd/mm/yyyy'

});

If by Class:

如果按类别:

$('.datepicker').datepicker({
    format: 'dd/mm/yyyy'

});

回答by Bhumika Vaza

File name : bootstrap-datepicker.jsLine No : 41:

文件名:bootstrap-datepicker.js行号:41:

this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');

回答by Nguy?n Hoàng Ch??ng

Easy way:

简单的方法:

Open the file bootstrap-datepicker.js

打开文件 bootstrap-datepicker.js

Go to line 1399 and find format: 'mm/dd/yyyy'.

转到第 1399 行并找到format: 'mm/dd/yyyy'.

Now you can change the date format here.

现在您可以在此处更改日期格式。

回答by Ezra

for me with bootstrap 4 datetime picker (http://www.eyecon.ro/bootstrap-datepicker/) format worked only with upper case:

对我来说,bootstrap 4 日期时间选择器(http://www.eyecon.ro/bootstrap-datepicker/)格式只适用于大写:

$('.datepicker').datetimepicker({
            format: 'DD/MM/YYYY'
        });

回答by rendzzx

thisworks for me

对我有用

Open the file bootstrap-datepicker.js

打开文件 bootstrap-datepicker.js

Go to line 1399 and find format: 'mm/dd/yyyy'.

转到第 1399 行并找到format: 'mm/dd/yyyy'.

Now you can change the date format here.

现在您可以在此处更改日期格式。

回答by Carmel Nkesh

  $(function () {
    $('.datetimepicker').datetimepicker(
      {
        format: 'Y-m-d h:m:s'
     }
    );
 });`

回答by Khadka Pushpendra

If you are using new jqueryui above code will not help you use this

如果您使用的是新的 jqueryui 上面的代码将无法帮助您使用它

$('.datepicker').datepicker({dateFormat:"yy-mm-dd"});