How to Convert Gmt Time to Ist Time in Javascript

i'm getting time like this - 2018-06-08T08:52:51.871Z. i want to convert it like 08-06-2018 2.42 PM. how to convert GMT to IST using angular js.

html

 <td>{{names.timestamp}}</td>

Javascript

<script>
    function base64toHEX(base64) {
        var raw = atob(base64);
        var HEX = '';
        for (i = 0; i < raw.length; i++) {
            var _hex = raw.charCodeAt(i).toString(16)
            HEX += (_hex.length == 2 ? _hex : '0' + _hex);
        }
        return HEX.toUpperCase();
    }
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function ($scope, $http) {
        $http.get('url', {
            headers: { 'Authorization': 'Basic a2VybmVsc3BoZ==' }
        })
           .then(function (response) {
               $scope.names = response.data;
               $scope.decodedFrame =base64toHEX($scope.names.dataFrame);
        });
    });
</script>
1

5 Answers

use the angular filter to format the date and timezone

<td>{{names.timestamp | date:'MM-dd-yyyy HH:mm:ss'| timezone: '+0430'}}</td>

You can use a built-in filter for dates:

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.timestamp = new Date("2018-06-08T08:52:51.871Z");
});
<script src=""></script>

<div ng-app="myApp" ng-controller="myCtrl">

  GMT: {{timestamp | date: 'dd-MM-y h:mm a'}}
  <hr>
  IST: {{timestamp | date: 'dd-MM-y h:mm a' : '+0430'}}

</div>
2

use angular pipe In HTML Template Binding

{{ date_expression | date : format : timezone}}

You can do this with the angularJS Pipe

{{ names.timestamp | date : 'mm-dd-yyyy hh.mm a'}}}

also you can check and show date what you want

{{names.timestamp | date : "dd-MM-y hh.mm a"}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest