Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • AngularJS md-datepicker format

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.22k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: