【问题标题】:How can I display the right dateformat with angular bootstrap datepicker?如何使用角度引导日期选择器显示正确的日期格式?
【发布时间】:2015-12-07 10:47:06
【问题描述】:

我正在使用引导日期选择器进行 Angular,但在显示正确的日期格式时遇到问题。我现在得到的格式是: “2015-09-08T00:56:40.272Z”。我想要的格式是dd-mmm-yyyy。

这是我的日期选择器:

<p class="input-group">

  selected date:{{dt}}

    <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt"
           is-open="opened" datepicker-options="dateOptions"
           date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" my-date/>

              <span class="input-group-btn">

                <button type="button" class="btn btn-default" ng-click="open($event)"><i
                        class="glyphicon glyphicon-calendar"></i></button>

              </span>
</p>

我试过这个: Angular bootstrap datepicker date format does not format ng-model value.

但没有解决问题。如何获得正确的日期格式?

plunkr:http://plnkr.co/edit/CbNHCl?p=preview

【问题讨论】:

标签: angularjs twitter-bootstrap


【解决方案1】:

你的意思是你在哪里有selected date:{{dt}}?您只需使用date 过滤器对其进行格式化

selected date:{{dt | date:format}}

这是因为您的 dt 模型将是一个 Date 实例。

http://plnkr.co/edit/zKWXwb?p=preview

【讨论】:

  • 当我想在 js 中设置它时可以吗?类似于 = $filter('date')($scope.dt, $scope.format) ?
猜你喜欢
  • 2023-04-09
  • 2016-08-20
  • 1970-01-01
  • 2018-12-31
  • 2020-04-09
  • 1970-01-01
  • 2017-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多