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 />
1

2 Answers 2

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

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

Comments

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

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.