0

I am getting date format like this /Date(1497683045200)/.
I want to convert it as dd/MM/yyyy. I tried this

 <td>{{data.From |  date:'MM/dd/yyyy' }}</td>

But format is not changed.Any suggestion?

2

2 Answers 2

1

create a custom filter like this

.filter('jsonDate',function(){
  return function(date){
    return new Date(date.match(/\d+/)[0] * 1);
  }
})

call it like this

<td>{{data.From |  jsonDate |  date:'MM/dd/yyyy'}}</td>
Sign up to request clarification or add additional context in comments.

2 Comments

thanks. But am getting like this "2017-06-18T18:30:00.000Z" can I use dd/MM/yyyy filter after jsonDate
@user7397787 use it like this <td>{{data.From | jsonDate | date:'MM/dd/yyyy'}}</td>
1

try this

formatDate(date) {
        let d = new Date(date),
            month = '' + (d.getMonth() + 1),
            day = '' + d.getDate(),
            year = d.getFullYear();
        if (month.length < 2) month = '0' + month;
        if (day.length < 2) day = '0' + day;
        return [ month, day, year].join('/');
    }

Call that custom method on HTML

<td>{{formatDate(data.From)}}</td>

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.