Hi,
Today we will discuss how to define our custom date format for md-datepicker in angularJS.
1. You will need to install moment.js from nuget packages
2. Add reference of moment.min.js
<script src="~/Scripts/moment.min.js"></script>
3. Add below code snippet in your angularJS
app.config(['$mdDateLocaleProvider', function ($mdDateLocaleProvider) {
$mdDateLocaleProvider.formatDate = function (date) {
return date ? moment(date).format('DD/MM/YYYY') : '';
};
$mdDateLocaleProvider.parseDate = function (dateString) {
var m = moment(dateString, 'DD/MM/YYYY', true);
return m.isValid() ? m.toDate() : new Date(NaN);
};
}]);
And yes that's that simple.....
Happy Coding...
0 Comment(s)