【问题标题】:How to change the date format in Bootstrap date picker?如何更改 Bootstrap 日期选择器中的日期格式?
【发布时间】:2019-04-18 04:16:05
【问题描述】:

在我的表单中,我有以下代码来显示date picker。我正在使用bootstrap

                         <div class="form-group row">
                                <label for="Quantity" class="col-sm-3 col-form-label">Required Date</label>
                                <div class="col-sm-9">
                                    <div class="input-group">                                        
                                        <input class="form-control" id="date" name="date" placeholder="MM/DD/YYYY" type="text"/>
                                        <div class="input-group-addon">
                                            <i class="fas fa-calendar-alt"></i>
                                        </div>
                                    </div>
                                </div>
                            </div>

我得到的日期格式是 MM/DD/YYYY。但我需要的格式是 DD/MM/YYYY。我怎样才能改变这个?如果我可以向表单字段添加属性,而不是 jquery 的 javascript。

【问题讨论】:

    标签: javascript html css twitter-bootstrap twitter-bootstrap-3


    【解决方案1】:

    您需要在jQuery 中定义一次格式。

    // here assumed that `datepicker` is the class name for using date picker
    $('.datepicker').datepicker({
        format: 'DD/MM/YYYY'
    });
    
    // as per your code, you can update for specific id
    $('#date').datepicker({
        format: 'DD/MM/YYYY'
    });
    

    【讨论】:

    • 那不是类名。反正我可以定义一个ID。但是我应该在哪个元素中定义它?
    • 是的,同意。由你决定。我补充说,您可以为整个站点上的所有日期选择器设置格式:) 请接受答案。
    • 不,答案没有解决问题。我应该向哪个元素添加 ID?你能用相关 JQuery 更改的 HTML 更改来更新你的答案吗?
    • 请看看现在的答案。我添加了两个选项。更新 id 或整个网站作为格式级别的东西应该在网站级别完成。
    • 刚刚尝试过,不幸的是没有用 :( 我在控制台中收到此错误 - Uncaught TypeError: $(...).datetimepicker is not a function
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 2018-02-19
    • 1970-01-01
    • 2015-12-24
    相关资源
    最近更新 更多