简体   繁体   中英

How to change value notation of date input field in AngularJS

I would like to change format of date input field from dd/mm/yyy to dd.mm.yyyy Is it possible and how and is there any chance to get that datepicker working in another browsers as well?

<body ng-app="myApp">
    <div ng-controller="MyCtrl">
      <input type="date" ng-model="date" value="{{date}}">
        <p>{{date}}</p>
      <input type="time" ng-model="time" value="{{time}}">    
    </div>

Chrome浏览器中的日期现在看起来如何

you can use custom filter for it as below

        <div ng-app="myApp">
           <div ng-controller="myCtrl">
             <p>{{date | divideByPoint}}</p> // displays as dd.mm.yyyy(21.12.2014)
          </div>
       </div>

below filter : divideByPoint

      var app = angular.module('myApp',[]);

 //controller
      app.controller('myCtrl',myCtrl);

         myCtrl.$inject = ["$scope"];

         function myCtrl($scope){
            $scope.date = "21/12/2014"
       }

  //filter

    app.filter('divideByPoint',function(){

     var pattern = /\//g;  
        return function(input) {
              return input.replace(pattern,'.');
           }

     })

https://jsfiddle.net/shushanthp/9yes55L5/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM