I am trying to format date using moment in Angularjs but its not working 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');
}
AngularJS has a built in filter for dates. You do not need to use moment, waste of resources.
<span>{{message.time | date}}</span>
https://docs.angularjs.org/api/ng/filter/date
I've used angular-moment successfully in a project of mine. It has a filter that alows you to format the date. Example from the README:
<span>{{message.time | amDateFormat:'dddd, MMMM Do YYYY, h:mm:ss a'}}</span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With