[英]How to convert date format in angular bootstrap date picker
我正在使用角度日期選擇器。 當用戶選擇日期時,我想過濾結果。
我已經在日期選擇器中添加了ng-change,它正在檢測更改並傳遞日期值。 但是格式不正確。
<uib-datepicker ng-model="dt" ng-change="dateSelected('{{dt}}')" class="well well-sm" datepicker-options="options"></uib-datepicker>
控制者
$scope.dateSelected = function(passedDate){
console.log('Date Selected ' + passedDate);
}
這給
2016-04-26T12:18:56.794Z
我如何將其轉換為
18 March, 2016
或類似的東西。
我通過基於文檔更新$ scope.options嘗試了幾個選項,但是沒有任何效果。
嘗試這個:
html應該像這樣,您不需要在ng-change中使用{{}}
<uib-datepicker ng-model="dt" ng-change="dateSelected(dt)" class="well well-sm" datepicker-options="options"></uib-datepicker>
var monthArray = ["January", "February", "March", "April",....];
和JS應該像
console.log($scope.dt.getDate()+', '+monthArray[$scope.dt.getMonth()]+', '+$scope.dt.getFullYear());
HTML中的日期選擇器
<div class="input-group ui-datepicker">
<input type="text"
class="form-control date"
datepicker-popup="{{format}}"
ng-model="dt"
is-open="opened"
min-date="minDate"
max="'2015-06-22'"
ng-readonly="true"
datepicker-options="dateOptions"
date-disabled="disabled(date, mode)"
ng-required="true"
close-text="Close" style="cursor:auto;">
<span class="input-group-addon" ng-click="open($event)"><i class="fa fa-calendar"></i></span>
</div>
將格式設置為:
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.