convert UTC to local time using angularjs

前端 未结 4 2029
梦谈多话
梦谈多话 2020-12-16 01:08

As a response from the json I am getting the UTC timezone. I need to convert it to local time.

{{trans.txnDate}}         


        
4条回答
  •  Happy的楠姐
    2020-12-16 01:46

    I had the same issue. AngularJs's date filter doesn't figure out the string is UTC format, but JavaScript Date object does. So I created a simple function in the Controller:

    $scope.dateOf = function(utcDateStr) {
        return new Date(utcDateStr);
    }
    

    And then used something like:

    {{ dateOf(trans.txnDate) | date: 'yyyy-MM-dd HH:mm:ss Z'  }}
    

    It displays the date/time in the local timezone

提交回复
热议问题