Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date Time format too complex when bind the value, AngularJS

I have a datepicker on my angularJS WCFrest project

enter image description here

i get the data using

<div class="col-md-4">
  <input id="txtOldDate" type="date" class="datepicker" ng-model="oldDate" />
</div>

but the data that acquired is too complex when i get the data

Fri Dec 16 2016 00:00:00 GMT+07 (SE Asia Standard Time)

i just want to get the value like on the date picker interface

12/16/2016

this is my controller.js

$scope.SearchApproval = function(employeeID, oldDate, newDate, departemen, approver) {
  var promiseGet = GetApproval.GetApprovalData($scope.employeeID, $scope.oldDate, $scope.newDate, $scope.departemen, $scope.approver);
  //GetApprovalData();
  promiseGet.then(function(pl) {
      $scope.GetApprovalData = pl.data
    },
    function(errorPl) {
      console.log('Some Error in Getting Records.', errorPl);
    });
}

is there any way to format the result?

i already try $filter

$scope.oldDate = $filter('date')(new Date(dateString), 'yyyy-MM-dd');

but it give me this error

Error: [ngModel:datefmt] Expected 2016-12-20 to be a date

like image 379
Jackie Avatar asked Dec 20 '16 07:12

Jackie


1 Answers

Take a look at this Angular Moment Js and Moment Js it might be helpful.

You can convert this as the below using moment js

$scope.oldDate = moment(dateString).format("YYYY-MM-DD");

To use this you have to add Angular moment in your project and which is explained in above link how to add using nuget or bower or npm.

like image 149
Curiousdev Avatar answered Oct 28 '22 00:10

Curiousdev