Philip7899 Philip7899 - 1 year ago 55
AngularJS Question

moment.js in angular is not formatting as I would expect

I have a Time being pulled from a server in the following JSON format:


I am using momentjs with angular with the following filter:

{{event_details.begins_at | moment: "format": "HH:MM a"}}

I would expect the following output:
08:11 am
. Instead, I am getting:
04:04 am
. I suspect it might have something to do with timezones, but I'm not sure. How do I fix this?

Answer Source

Change MM to mm (months to minutes : ))

angular.module('app', [])
  .provider('moment', function() {  // be nice for DI
    this.$get = function() {
      return moment
  .controller('ctrl', function() {
    this.event_details = {
      begins_at: '2016-04-22T08:11:07.000Z'
  .filter('moment', function(moment) {
    return function(input, options) {
      return moment(input).format(options.split('\'')[1]) // ugly formatter ; (
<script src=""></script>
<script src=""></script>

<div ng-app='app'>
  <div ng-controller='ctrl as c'>
    moment: {{ c.event_details.begins_at | moment:"format: 'HH:mm a'" }}