[英]change format date datepicker angular material
I am learning and trying to understand how the angularJS framework works, I managed to display a datepicker but I can not change the format of the current date (mm-dd-yyyy). 我正在学习并试图了解angularJS框架的工作原理,设法显示了一个日期选择器,但无法更改当前日期的格式(mm-dd-yyyy)。 I want to change this format to the local date of the user, fr-FR, en-GB ...
我想将此格式更改为用户的本地日期,fr-FR,en-GB ...
I saw this documentation there but I do not know in which part of the code paste the examples ... 我在那里看到了此文档 ,但我不知道代码将示例粘贴到了哪一部分...
I also tried this 我也尝试过
angular.module('BlankApp', ['ngMaterial']);
var app = angular.module('myApp', []);
app.config(function($interpolateProvider){
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
});
myAppModule.config(function($mdDateLocaleProvider) {
// Example of a French localization.
$mdDateLocaleProvider.months = ['janvier', 'février', 'mars'];
$mdDateLocaleProvider.shortMonths = ['janv', 'févr', 'mars'];
$mdDateLocaleProvider.days = ['dimanche', 'lundi', 'mardi'];
$mdDateLocaleProvider.shortDays = ['Di', 'Lu', 'Ma'];
// Can change week display to start on Monday.
$mdDateLocaleProvider.firstDayOfWeek = 1;
// Optional.
$mdDateLocaleProvider.dates = [1, 2, 3, 4, 5, 6];
// Example uses moment.js to parse and format dates.
$mdDateLocaleProvider.parseDate = function(dateString) {
var m = moment(dateString, 'L', true);
return m.isValid() ? m.toDate() : new Date(NaN);
};
$mdDateLocaleProvider.formatDate = function(date) {
var m = moment(date);
return m.isValid() ? m.format('L') : '';
};
$mdDateLocaleProvider.monthHeaderFormatter = function(date) {
return myShortMonths[date.getMonth()] + ' ' + date.getFullYear();
};
// In addition to date display, date components also need localized messages
// for aria-labels for screen-reader users.
$mdDateLocaleProvider.weekNumberFormatter = function(weekNumber) {
return 'Semaine ' + weekNumber;
};
$mdDateLocaleProvider.msgCalendar = 'Calendrier';
$mdDateLocaleProvider.msgOpenCalendar = 'Ouvrir le calendrier';
// You can also set when your calendar begins and ends.
$mdDateLocaleProvider.firstRenderableDate = new Date(1776, 6, 4);
$mdDateLocaleProvider.lastRenderableDate = new Date(2012, 11, 21);
});
in the html code: 在html代码中:
<md-datepicker ng-model="creation" ui-date="{ dateFormat: 'yy-mm-dd' }"></md-datepicker>
Did you try it with ng-model-options? 您是否尝试过ng-model-options? Like their api talks:
像他们的api演讲:
mdDatepicker: https://material.angularjs.org/latest/api/directive/mdDatepicker mdDatepicker: https ://material.angularjs.org/latest/api/directive/mdDatepicker
ngModelOptions: https://docs.angularjs.org/api/ng/directive/ngModelOptions#usage ngModelOptions: https ://docs.angularjs.org/api/ng/directive/ngModelOptions#usage
PD: Remember you're using angular material for angular 1 version PD:请记住,您正在使用角材料制作角1版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.