moment

by Greg Wang

HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.js"></script>
<div ng-app="myApp">
    <div ng-controller="myCtrl">
        <div>{{ date | moment:'format':'dddd, MMMM Do YYYY, h:mm:ss a' }}</div>
        <div>{{ date | moment:'fromNow' }}</div>
        <div>{{ date | moment:'fromNow':true }}</div>
        <div>{{ date | moment:'from':[2007, 0, 28] }}</div>
        <div>{{ date | moment:'calendar' }}</div>
        <div>{{ date | moment:'calendar':[2007, 0, 28] }}</div>
        <div>{{ date | moment:'unix' }}</div>
        <div>{{ date | moment:'daysInMonth' }}</div>
        <div>{{ date | moment:'toDate' }}</div>
        <div>{{ date | moment:'toArray' }}</div>
        <div>{{ date | moment:'toJSON' }}</div>
        <div>{{ date | moment:'toISOString' }}</div>
    </div>
</div>

JavaScript

(function () {
  'use strict';

  angular.module('myApp', [])
  .filter('moment', [
    function () {
      return function (date, method) {
        var momented = moment(date);
        return momented[method].apply(momented, Array.prototype.slice.call(arguments, 2));
      };
    }
  ])
  .controller('myCtrl', function($scope) {
      $scope.date = new Date();
  });
}());