0

I am facing very strange issue with angular-ui bootstrap calendar.

Here is the sample i have created

http://plnkr.co/edit/V5UgCbfilCXX8nsube12?p=preview

The scenario is that when page land it shows right date in ng-model variable however when i am selecting date from calendar ng-model shows date in UST.

e.g. when i select date from calendar as "01/05/2012" ng-model binded property shows as "2012-01-04T18:30:00.000Z". I want what is in textbox i.e. "01/05/2012".

How to overcome this issue.

<!doctype html>
<html ng-app="ui.bootstrap.demo">
 <head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<script>
    angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
    angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($scope) {
      $scope.today = function() {
        $scope.dt = new Date();
      };

      $scope.dates = [{ date:'01/01/2012',isOpen:false, isDisabled:false}, {date:'05/05/2000',isOpen:false, isDisabled:false}, {date:'',isOpen:false, isDisabled:true}];

      $scope.today();

      $scope.clear = function () {
        $scope.dt = null;
      };

      // Disable weekend selection
      $scope.disabled = function(date, mode) {
        return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
      };

      $scope.toggleMin = function() {
        $scope.minDate = $scope.minDate ? null : new Date();
      };
      $scope.toggleMin();

      $scope.open = function($event, date) {
        $event.preventDefault();
        $event.stopPropagation();
        date.isOpen=true;
        $scope.opened = true;
      };

      $scope.dateOptions = {
        formatYear: 'MM/dd/yyyy',
        startingDay: 1
      };

      $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
      $scope.format = 'MM/dd/yyyy';
    });
</script>
 </head>
 <body>

<div ng-controller="DatepickerDemoCtrl">
    <h4>Popup</h4>
    <br/>
<br/>
My Dates object {{dates}}
<br/>
<br/>
<div class="row" ng-repeat='x in dates'>
<span style="margin-left:20px">{{x.date}}</span>
    <div class="col-md-6">
        <p class="input-group">
          <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="x.date" is-open="x.isOpen" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
          <span class="input-group-btn">
            <button type="button" ng-disabled="x.isDisabled" class="btn btn-default" ng-click="open($event,x)"><i class="glyphicon glyphicon-calendar"></i></button>
          </span>
        </p>
    </div>
    <br/>
<br/>
</div>
<hr />
</div>
  </body>
</html>

2 Answers 2

0

You actually have the right value on your model. The .000Z is the fraction of a second and Z indicates UTC timezone.

Sign up to request clarification or add additional context in comments.

Comments

0

It has the same issue here:

Angular bootstrap datepicker date format does not format ng-model value

And its being answered by some. You can refer the link above.

It works for me!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.