Change format of md-datepicker in Angular Material with momentjs

前端 未结 13 783
再見小時候
再見小時候 2020-11-28 09:01

Angular material introduced a new date picker component found here.

I want the date returned by this component to be in the format yyy-mm-dd but I am not su

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 09:39

    There is a documentation for $mdDateLocaleProvider in the Angular Material docs.

    angular.module('app').config(function($mdDateLocaleProvider) {
        $mdDateLocaleProvider.formatDate = function(date) {
           return moment(date).format('YYYY-MM-DD');
        };
    });
    

    If you don't use moment.js, substitute the code inside formatDate for whatever you wish to use to format the date.

    Here is a CodePen example based on the samples from Angular Material docs.

提交回复
热议问题