简体   繁体   English

如何更改 html 日期选择器的日期格式

[英]How to change date format of html date picker

I am using AngularJs to create a form where I need to add a date picker which should show date in format of mm-dd-yyyy .我正在使用 AngularJs 创建一个表单,我需要在其中添加一个日期选择器,它应该以mm-dd-yyyy的格式显示日期。 But the default HTML5 date picker shows date in dd-mm-yyyy format.但是默认的 HTML5 日期选择器以dd-mm-yyyy格式显示日期。 Is there any way to show date in mm-dd-yyyy format?有没有办法以mm-dd-yyyy格式显示日期?

My code -我的代码 -

<div>
    <div class="col-md-6">
        <div  class="position-relative form-group">
            <label for="123" class="font-weight-bold">Date of Birth <span class="text-danger">*</span></label>
            <div id="dob" class="input-group date">
                <input type="date" class="form-control required" id="dob" ng-model="data.DOB" required />
            </div>
        </div>
    </div>
    <button ng-click="submit(data)">Submit</button>
</div>
 

$scope.submit = function(data) {
            console.log(data);
        }

How can I achieve this?我怎样才能做到这一点?

The displayed date format will differ from the actual value — the displayed date is formatted based on the locale of the user's browser, but the parsed value is always formatted yyyy-mm-dd.显示的日期格式将与实际值不同 — 显示的日期根据用户浏览器的区域设置进行格式化,但解析的值始终采用 yyyy-mm-dd 格式。

Check this for more details - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date检查此以获取更多详细信息 - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM