且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AngularJS:如何格式化 ISO8601 日期格式?

更新时间:2023-02-20 09:47:44

现在,我已经创建了一个过滤器

For now, I have created a filter

angular.module('customFilters', []).
  filter('dateInMillis', function() {
    return function(dateString) {
      return Date.parse(dateString);
    };
  });

app.js 中作为依赖添加为

added as dependency in app.js as

var app = angular.module('myApp', [
  '$strap.directives', 'ngCookies', 'categoryServices', 'transactionServices',
  'customFilters'
]);

并在 HTML 中将其用作

<!-- added dateInMillis to pass to date to filter Angular way -->
<td>{{ transaction.created_on | dateInMillis | date: 'medium'}}</td>

并且将 HTML 上的日期显示为

and that presents date on HTML as

May 8, 2013 5:14:36 PM 

如果你有更好的想法,请告诉我

If you know a better idea, please let me know