BKM
BKM

Reputation: 186

change format of date in angularJS

i am getting date with time but i want to remove the time and make the format as 16-oct-2019 instead of 16-10-2019T 00:00:00

<tr ng-repeat="action in Action">
            <td>{{ $index + 1 }}</td>
            <td id="Td1" runat="server" visible="false">{{action.sId}}</td>
            <td>{{action.A}}</td>
            <td>{{action.B}}</td>
            <td>{{action.C}}</td>
            <td>{{action.D}}</td>
            <td>{{(action.Date)}}</td>
</tr>

Upvotes: 0

Views: 58

Answers (2)

upinder kumar
upinder kumar

Reputation: 837

I have created one Pipe for Data Format :

import { Pipe, PipeTransform } from '@angular/core';
import { DatePipe } from '@angular/common';

const DATE_FORMATE = 'dd-MMM-yyyy';
@Pipe({
  name: 'dateFormat'
})
export class DateFormatPipe extends DatePipe implements PipeTransform {

  transform(value: string, args?: any): any {
    const onlyDateValue = value.split('T')[0];
    return super.transform(onlyDateValue, DATE_FORMATE);
  }

}

in the template:

<tr ng-repeat="action in Action">
            <td>{{ $index + 1 }}</td>
            <td id="Td1" runat="server" visible="false">{{action.sId}}</td>
            <td>{{action.A}}</td>
            <td>{{action.B}}</td>
            <td>{{action.C}}</td>
            <td>{{action.D}}</td>
            <td>{{(action.Date) | dateFormat }}</td>
</tr>

Upvotes: 0

Bill P
Bill P

Reputation: 3616

Try this angular filter:

<td>{{ action.Date | date: 'd-MMM-y' }}</td>

Upvotes: 3

Related Questions