0

I want to show date with format 'MM/dd/yyyy'.
The date filter working but that format of date part doesn't working.

the following one is my code:

this.$filter('date')(this.BeginDate, 'MM/dd/yyyy')
4
  • 2
    Is BeginDate definitely a DateTime object? Commented Dec 18, 2017 at 9:38
  • @phuzi BeginDate can also be a string or a timestamp Commented Dec 18, 2017 at 9:40
  • @svarog true, it could be a string but it would have to formatted as a datetime that JS would be able to interpret as a datetime. If it's a DateTime object or a timestamp then there is no ambuiguity. Commented Dec 18, 2017 at 9:59
  • just stating what's in the docs Commented Dec 18, 2017 at 10:22

1 Answer 1

1

here is a quick example of what you need, check the way you call the filter in your controller

angular.module('myApp',[])
.run(function($rootScope,$filter){

  $rootScope.date = $filter('date')(new Date(),'MM/dd/yyyy'); // the issue is here
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  {{date}}
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.