Home Format datepicker not change angularjs
Reply: 1

Format datepicker not change angularjs

Andika Ristian Nugraha
1#
Andika Ristian Nugraha Published in 2017-11-14 17:57:03Z

i have define the format for my datepicker like this

    $scope.open1 = function() {
    $scope.popup1.opened = true;
  };

  $scope.open2 = function() {
    $scope.popup2.opened = true;
  };
  $scope.formats = ['dd-MMMM-yyyy', 'yyyyMMdd'];
  $scope.format = $scope.formats[1];
  $scope.dt = new Date();
  $scope.dt2 = new Date();
  console.log($scope.dt);
  $scope.popup1 = {
    opened: false
  };

  $scope.popup2 = {
    opened: false
  };

but when i console.log, the result becoming like this

i want something like when i console.log the result will be same as i define. for example Tue Nov 14 2017 into 20171114

here is my .html file

<div class="col-md-2">
        <p class="input-group">
          <input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="dt2" is-open="popup2.opened"/>
          <span class="input-group-btn">
            <button type="button" class="btn btn-default" ng-click="open2()"><i class="glyphicon glyphicon-calendar"></i></button>
          </span>
        </p>
        </div>
Andika Ristian Nugraha
2#
Andika Ristian Nugraha Reply to 2017-11-16 03:58:09Z

it works for me, hope it helps

var d = new Date($scope.dt);
  var curr_year = d.getFullYear();
  var curr_Month = d.getMonth()+1;
          if (curr_Month.toString().length < 2) {
            var curr_Month = "0" + (d.getMonth()+1);
          } else {
            var curr_Month = d.getMonth()+1;
          }
          //alert(curr_Month);

          var curr_date = d.getDate();
          if (curr_date.toString().length<2) {
            var curr_date = "0"+ d.getDate();
          } else {
            var curr_date = d.getDate();
          }
          //alert(curr_date);
          var todayDate = (curr_year + "" + (curr_Month) + "" + curr_date);
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316475 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO