1

I have a datestring in the following format: YYYY-MM-DD HH:mm:SS

I want to use the Angular date filter in the binding to change it to a YYYY-MM-DD HH:mm format.

I am trying {{data.date | date : "YYYY-MM-DD HH:mm"}}, but it doens't seem to work. Any ideas on what to change to get it to recognize my date format?

1 Answer 1

3

Try this

In Js file

angular.module('yourmodule').filter('datetime', function($filter)
{
 return function(input)
 {
  if(input == null){ return ""; } 

  var _date = $filter('date')(new Date(input),
                              'MMM dd yyyy - HH:mm:ss');

  return _date.toUpperCase();

 };
});

In HTML

<span>{{ d.time | datetime }}</span>
Sign up to request clarification or add additional context in comments.

1 Comment

I'm trying to do the filtering in the HTML and not the javascript.

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.