gmt到angularjs中的本地时间格式

时间:2016-09-23 13:14:01

标签: angularjs

我从php服务器"2016-09-14 12:50 PM GMT"得到它。试图像"sep 9, 2016"

那样展示它

角:

var request = $http({
      method: "get",
      url: "dashboardServiceCall.php",
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    });

    /* Successful HTTP get request or not */
    request.success(function (data, status, headers, config) {
        z=0;
        for(var x=0; x < data.length; x++){
          if(data[x]['type'] == 1){
              $scope.getdatewasedetails[z] = data[x]['data']['dateWaseReportResForTests'][0];
              z++;
          }

          if(data[x]['type'] == 2){
              for(var y=0; y<data[x]['data']['dateWaseReportResForGroups'].length; y++){
                  $scope.getdatewasedetails[z] = data[x]['data']['dateWaseReportResForGroups'][y]['data']['dateWaseReportResForTests'][0];
                  z++;
              }
          }
      }
    });         

结果Json结构:

documentation

HTML:

<tr ng-repeat="visits in getdatewasedetails | orderBy: '-testDate' | limitTo: 5" ng-class="{'criticalValue' : visits.testResult > visits.highValue || visits.lowValue > visits.testResult}" >
                                        <td>{{visits.testDate | date:'longDate'}}</td>

</tr>

我尝试了很少的更改,例如angular timezone但是失败了。任何帮助都会很棒。提前谢谢。

1 个答案:

答案 0 :(得分:1)

您需要日期对象才能使用日期过滤器。

尝试:

obj.testDate = new Date(obj.testDate.slice(0,10));