【问题标题】:Show date in date range format in angular以角度日期范围格式显示日期
【发布时间】:2016-05-07 16:11:56
【问题描述】:

点击DATEPICKER了解我的问题。 此处显示的日期格式为“d-d M yyyy”。 EditText(在图像DATEPICKER)中显示的日期是“2016 年 5 月 18 日至 18 日”。 但我想将其显示为“2016 年 5 月 18 日至 21 日”。那么,有没有办法(任何格式)将日期显示为“2016 年 5 月 18 日至 21 日”。

我正在使用带有下面给出的链接的引导日期选择器。

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/css/bootstrap-datepicker3.min.css" rel="stylesheet">

我给这个日期选择器的一些默认选项是

    autoclose: true,
    todayHighlight: true,
    clearBtn: true
    format: 'd-d M yyyy',

另外,我正在使用 date-setter-directive,如下所示。

app.directive('dateSetter', function(){

return {
    restrict: 'A',
    require: '?ngModel',
    link: function(scope, element, attrs, ctrl){
        ctrl.$parsers.push(function (value) {
            if (!!value)
                return moment(value).format("YYYY-MM-DD");
            else
                return null;
        });

        ctrl.$formatters.push(function (value) {
            if (!!value) {
                return moment(value).format('ddd D MMM YYYY');
            }
            else
                return null;
        });
    }
}

});

【问题讨论】:

  • 您不能在一个日期中表示几天的范围。这不是格式问题,您需要两个变量,一个用于存储开始日期,另一个用于存储结束日期。

标签: angularjs bootstrap-datepicker


【解决方案1】:

angularjs 中的日期格式参考https://docs.angularjs.org/api/ng/filter/date

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多