g00fy- / angular-datepicker

calendar and datepicker directives for angular
MIT License
719 stars 420 forks source link

Angular DatePicker - Unable to get the accurate date in controller #320

Open chinmay235 opened 7 years ago

chinmay235 commented 7 years ago

I have faced datepicker issue can you please see https://angularjscript.github.io/angularjs-datepicker/chinu.html link. When I am selecting any date I am getting previous date from the input date. I select 2017-02-15 I am getting "due_date": "2017-02-14T19:00:00.000Z" in my controller.

2017-02-02_183604

Thanks @chinmay235

chinmay235 commented 7 years ago

I got one solution for getting accurate date. Here is my code:

<input type="datetime" class="form-control" name="due_date" date-time view="date" format="YYYY-MM-DD" auto-close="true" min-view="date" ng-model="formData.due_date" readonly="" required="" date-change="changeDueDate" />

$scope.changeDueDate = function (modelName, newDate) {
          console.log(modelName + ' has had a date change. New value is ' + newDate.format());
          $scope.formData.due_date = newDate.format();
 }