AngularJS get formatted date in ng-model

前端 未结 3 1768
星月不相逢
星月不相逢 2020-12-18 18:38

I have following text input filled by model value in timestamp:



        
相关标签:
3条回答
  • 2020-12-18 19:19

    You can also specify a timezone like this:

    $scope.$watch('workerDetail.dateOfBirth', function (newDate) {
        $scope.workerDetail.dateOfBirth = $filter('date')(newDate, 'HH:mm', 'UTC'); 
    });
    
    0 讨论(0)
  • 2020-12-18 19:20

    You can try a filter

    HTML

    <input type="datetime" ng-model="mydateOfBirth"  class="form-control" id="date_of_birth" />
    

    Controller JS

    $scope.$watch('mydateOfBirth', function (newValue) {
        $scope.workerDetail.dateOfBirth = $filter('date')(newValue, 'yyyy/MM/dd'); 
    });
    
    $scope.$watch('workerDetail.dateOfBirth', function (newValue) {
        $scope.mydateOfBirth = $filter('date')(newValue, 'yyyy/MM/dd'); 
    });
    
    0 讨论(0)
  • 2020-12-18 19:20

    Try This code to Get a date Only (dd/mm/yyyy)

    html

    <div class="col-lg-3">
    <input type="date" name="dob" class="input-lg form-group" ng-model='dob'>
    </div>
    

    Angularjs

    app.controller('myctrl',function($scope, $http,$window,$filter) {
    $scope.sent=function(){
        $scope.date = $filter("date")($scope.dob, 'dd-MM-yyyy');
        alert($scope.date);
    }})
    
    0 讨论(0)
提交回复
热议问题