在角材料MD-日期选择器的格式更改 [英] Change format of md-datepicker in Angular Material

查看:747
本文介绍了在角材料MD-日期选择器的格式更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

角材料引入了新的日期选择器组件中发现这里

Angular material introduced a new date picker component found here.

我想这个组件返回日期为格式的 YYY-MM-DD 的,但我不知道这是怎么完成的。通过搜索,我发现 $ mdDateLocaleProvider 可以使用,但我找不到使用它的一个例子。

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.

有人能告诉我格式化由 MD-日期选择器返回的日期的工作示例

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

推荐答案

有是<一个一个文件href=\"https://material.angularjs.org/latest/#/api/material.components.datepicker/service/$mdDateLocaleProvider\"><$c$c>$mdDateLocaleProvider在角材质文档。

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');
    };
});

如果你不使用moment.js,替换里面的 formatDate 的code任何你希望使用格式化的日期。

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

这里是$ C基于从角材料文档样本$​​ CPEN例子。

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

这篇关于在角材料MD-日期选择器的格式更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆