Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
75
rated 0 times [  76] [ 1]  / answers: 1 / hits: 95592  / 9 Years ago, mon, september 14, 2015, 12:00:00

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 sure how is this done. By searching I found that $mdDateLocaleProvider can be used, but I could not find an example of using it.



Can someone show me a working example of formatting the date returned by md-datepicker?


More From » angularjs

 Answers
7

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.


[#65072] Friday, September 11, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stephonkeandrer

Total Points: 392
Total Questions: 94
Total Answers: 100

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
;