2016-10-22 80 views
0

我能夠在HTML中顯示的時區,使用下面的代碼偏移量:如何顯示的時區的名稱,而不是偏移

<span class="match-date"> 
    {{match.match_date | date:'fullDate'}} at {{match.match_date | date:'shortTime'}} {{match.match_date | date:'Z'}} 
</span> 

導致:

Saturday, October 22, 2016 at 5:00 PM -0500 

不過我

Saturday, October 22, 2016 at 5:00 PM CDT 

我怎樣才能伴奏:希望它有偏移的樣子時區名稱,而不是顯示這是什麼?

+1

你應該使用'moment'它,通過'http:// momentjs.com/docs /#/ displays/format /' – Sravan

+0

你的約會怎麼樣? – Sajeetharan

+0

我也會像Sravan一樣建議moment.js。如果你不想要這種依賴性,你可以保留你自己的偏移量數組並做一個簡單的字符串替換? https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations – Luke

回答

1

下面是使用角動量的答案,

var app = angular.module('app', ['angularMoment']); 
 

 
app.controller('TestCtrl', function($scope, $timeout) { 
 
    $scope.obj = { 
 
    dateStr: "2013-10-02T23:28:37+0000" 
 
    }; 
 
    
 
    $scope.timezone= /\((.*)\)/.exec(new Date($scope.obj.dateStr).toString())[1]; 
 
    
 
    console.log("moment", $scope.obj.dateStr, moment($scope.obj.dateStr)); 
 
    
 
    
 
    
 
    
 
});
<!DOCTYPE html> 
 
<html> 
 

 
    <head> 
 
    <script data-require="[email protected]" data-semver="1.0.8" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script> 
 
    <script data-require="[email protected]" data-semver="2.1.0" src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.1.0/moment.min.js"></script> 
 
    <!--<script src="angular-moment.min.js"></script>--> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-moment/1.0.0/angular-moment.js"></script> 
 

 
    <link rel="stylesheet" href="style.css" /> 
 
    <script src="script.js"></script> 
 
    </head> 
 

 
    <body ng-app="app"> 
 
    <div ng-controller="TestCtrl"> 
 
     <h1>Hello Plunker!</h1> 
 
     <pre>{{ obj.dateStr | amDateFormat: 'h:mm a'}} {{timezone}}</pre> 
 
     
 
    </div> 
 
    </body> 
 

 
</html>

Please run the above snippet

Here is a plunker

相關問題