屏蔽 UI 日期选择器,将所选值格式化为 dd/MM/yyy

Shield UI Datepicker, Format Selected value to dd/MM/yyy

我正在使用 Shield UI 日期选择器来捕获 DOB,我在格式化所选日期时遇到问题。我使用的 JavaScript 代码如下所示

$("#dobPicker").shieldDatePicker({
    openOnFocus: true,
    format: "{0:dd/MM/yyyy}",
    textTemplate: "{0:dd/MM/yyyy}",
    parseFormats: ["dd/MM/yyyy"],
    max: new Date(),
    events: {
        change: function(e) {
            var dobVal = $("#dobPicker").swidget().value();
            alert(dobVal);
        }
    }
});

我得到的输出格式如下

2015 年 8 月 20 日星期四 00:00:00 GMT+0530(印度标准时间)

但我需要一个 dd/MM/yyyy 格式的输出

你能帮我解决这个问题吗?

提前致谢:)

Moment you can use. This is great library for handling date. CDN LINK 供您使用,也可以下载。

var dobVal = new Date();
console.log(dobVal);//output Sat Aug 22 2015 20:24:10 GMT+0530 (IST)
var formatted = moment(dobVal).format("DD/MM/YYYY");
console.log(formatted);//output 22/08/2015

DEMO

您可以将日期解析为标准日期并按照您想要的方式设置格式。

获得 value 后,您可以根据需要对其进行解析和格式化。 这是证明 here.