2

I want to convert below date and time to UTC format

"1970-05-11T18:30:00.000+0000"

I am able to do this inside view, but i want to do it in the controller.

{{stmt.tranDate | date:"dd/MM/yyyy": 'UTC'}}

controller

$scope.kycinfo.dob = "1970-05-11T18:30:00.000+0000";
$scope.dob = $filter('date')($scope.kycinfo.dob, "dd/MM/yyyy");

view

<input type="text" id="dateOfBirth" placeholder="Please Select ..."  data-ng-model="dob" name="dob" ng-required="true" mobi-date=true />
vishnu
  • 4,377
  • 15
  • 52
  • 89
  • Possible duplicate of [Using AngularJS date filter with UTC date](http://stackoverflow.com/questions/20662140/using-angularjs-date-filter-with-utc-date) – K K Feb 03 '16 at 07:00

2 Answers2

4

Pass "UTC" as third parameter to $filter('date).

$scope.kycinfo.dob = "1970-05-11T18:30:00.000+0000";
$scope.dob = $filter('date')($scope.kycinfo.dob, "dd/MM/yyyy", "UTC");

https://docs.angularjs.org/api/ng/filter/date

Siva
  • 2,735
  • 16
  • 14
0

i think you can try the following code:

 var toUTCDate = function(date){
    var _utc = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(),  date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
    return _utc;
  };

you can also visit Using AngularJS date filter with UTC date

Community
  • 1
  • 1
Python Basketball
  • 2,320
  • 3
  • 24
  • 47