stan
stan

Reputation: 468

how can I use datePipe in my component using angular?

Is there a way I can use the DatePipe in my angular component?

this is my code.

for (let i = 0; i < this.days.length; i++) {
      this.storeStart(this.days[i], null, null, null);
    }

Every weekday (monday to friday) is stored inside my days array. I want to store this with the other data inside of another array. Now I get this: 'Fri Nov 01 2019 00:00:00 GMT+0100'. But I only want it to display this: '01-11' (day-month). It's also being stored as a Date but I want to store this as a string. Can anyone help me out a bit?

Upvotes: 0

Views: 570

Answers (1)

Yash Rami
Yash Rami

Reputation: 2327

you can try like this by using a DI(dependency injection)

TS


for (let i = 0; i < this.days.length; i++) {
      let myDate = new DatePipe().transform(this.days[i], 'yyyy-MM-dd');
      this.storeStart(myDate, null, null, null);
}

Upvotes: 1

Related Questions