Cdc
Cdc

Reputation: 17

angular - Angular 6 how to I edit date format?

        <ng-container *ngFor="let column of columns">
      <ng-container *ngIf="column.isModelProperty" [matColumnDef]="column.property">
        <mat-header-cell *matHeaderCellDef mat-sort-header> {{ column.name }}</mat-header-cell>
        <mat-cell *matCellDef="let row">
          <span class="fury-mobile-label">{{ column.name }}</span>
          {{ row[column.property] }}
        </mat-cell>
      </ng-container>
    </ng-container>

export class Senderv2 {
    serviceCode: string;
    insertDate : DatePipe;

    constructor(senderv2) {
        this.serviceCode = senderv2.serviceCode;
        this.insertDate = senderv2.insertDate;
    }
}

export class ListColumn {
  name?: string;
  property?: string;
  visible?: boolean;
  isModelProperty?: boolean;
  displayFn: any;
}

The data comes from the database to the table. Data type datetime in the database Column property insertDate how to I edit date format?

Upvotes: 0

Views: 5058

Answers (1)

KShewengger
KShewengger

Reputation: 8269

You can edit you date in a custom format by using Angular's DatePipe.

Have attached a Stackblitz Demo for your reference

Sample Illustration:

import { DatePipe } from '@angular/common';


class Sender {

     currentDate: any = new Date();    

     constructor(private datePipe: DatePipe) {}   // Be sure to import this as a provider either inside Component or on your Module

     transformDate() {
         this.currentDate = this.datePipe.transform(this.currentDate, 'yyyy-MM-dd');  // 2018-11-23
     }

}

you can also refer to this answer for more information about implementing DatePipe

Upvotes: 1

Related Questions