简体   繁体   中英

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?

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM