Date format using Angularjs moment

I am trying to format a date using a moment in Angularjs but it does not work for me. Here is my fiddle http://jsfiddle.net/sed6x5e8/ , and below is my code.

HTML:

<div ng-app="miniapp"> <div ng-controller="Ctrl"> <div> Actual Date: {{date}} <br><br> Formatted Date: {{formattedDate}} </div> </div> </div> 

JS:

 var $scope; var app = angular.module('miniapp', []) function Ctrl($scope) { $scope.date = '2/13/2015'; $scope.formattedDate = moment($scope.date).format('YYYY-MM-DD'); } 
+7
javascript angularjs
source share
2 answers

I used angular-moment successfully in my project. It has a filter that allows you to format the date. Example from README:

 <span>{{message.time | amDateFormat:'dddd, MMMM Do YYYY, h:mm:ss a'}}</span> 
+5
source share

AngularJS has a built-in filter for dates. You do not need to use the moment, waste of resources.

 <span>{{message.time | date}}</span> 

https://docs.angularjs.org/api/ng/filter/date

+8
source share

All Articles