Bootstrap Datepicker —如何也获得其他格式的toDisplay和其他格式的toValue [英] Bootstrap datepicker — How to get toDisplay in other format and toValue in other format too

查看:90
本文介绍了Bootstrap Datepicker —如何也获得其他格式的toDisplay和其他格式的toValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很长时间以来,我在toValuetoDisplay上遇到麻烦.我需要并出现在显示屏上,以日期格式显示 dd.mm.yyyy 和u toValue,该日期以表格形式发送,因此其格式为 yyyy-mm-dd 格式.我尝试了各种方法,但仍然无法正常工作. 我在插件的官方页面上附加了代码.

For a long time, I'm having trouble with toValue and toDisplay. I need and appear on the display to show the date in format dd.mm.yyyy and u toValue, which is sent with the form so that it is in the yyyy-mm-dd format. I tried all kinds of things but it still does not work. I attach the code from the plugin's official page.

toDisplay: function (date, format, language) {
        var d = new Date(date);
        d.setDate(d.getDate() - 7);
        return d.toISOString();
},
toValue: function (date, format, language) {
        var d = new Date(date);
        d.setDate(d.getDate() + 7);
        return new Date(d);
}

预先感谢您的帮助!

推荐答案

 $("#elementID").datepicker({
        format: "dd/mm/yyyy", // or what ever format your want
        calendarWeeks: true,
        todayHighlight: true,
        clearBtn: true,
        autoclose: true
    });

然后在页面中包含moment.js库

Include moment.js library in your page then

var date = moment($('#elementID').datepicker("getDate")).format("YYYY/MM/DD");

这篇关于Bootstrap Datepicker —如何也获得其他格式的toDisplay和其他格式的toValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆