0

I have changes.lastUpdatedTime.currentValue which is 1540460704884 I want to use pipe for date format

e.g. {{lastUpdatedTime | date:'short'}}

How I can use | pipe inside the component.

${changes.lastUpdatedTime.currentValue} | date:'short'

something like this I want to use.

Code Below -

ngOnChanges(changes: SimpleChanges): void {
    if (changes.typeLabel && changes.cardLabel && changes.severity) {
      this.title = `[${this.severityName}] ${changes.cardLabel.currentValue}
Type: ${changes.typeLabel.currentValue}
Status changed: ${changes.lastUpdatedTime.currentValue}`;
    }
  }

I tried to use as below code but it's not working.

${changes.lastUpdatedTime.currentValue.transform(myDate, 'yyyy-MM-dd')};

I tried to use this - But it's not working.

  ngOnChanges(changes: SimpleChanges): void {
    if (changes.typeLabel && changes.cardLabel && changes.severity) {
      let displayedLastUpdatedTime = new DatePipe().transform(changes.lastUpdatedTime.currentValue);
      this.title = `[${this.severityName}] ${changes.cardLabel.currentValue}
Type: ${changes.typeLabel.currentValue}
Status changed: ${displayedLastUpdatedTime}`;
    }
  }

this gives error "has no exported member 'DatePipe'"

Thanks

Javascript Coder
  • 5,691
  • 8
  • 52
  • 98
  • why not apply the pipe in the html? if you have to do it in the component, you can import the pipe as a function – mast3rd3mon Dec 07 '18 at 09:12
  • My this.title if changing on every change, and I dont have last update time. – Javascript Coder Dec 07 '18 at 09:14
  • This is a duplicate, I have referred you to one of my answers explaining how to use the date pipe in a component. If you still have an issue after that, create a new question with a [mcve] reproducing the said issue –  Dec 07 '18 at 09:20
  • @trichetriche This is not duplicate. I still have an issue please check updated the question.. – Javascript Coder Dec 07 '18 at 09:34

1 Answers1

-1

I think, this is what you are looking for.

import {DatePipe} from '@angular/common';
let result = new DatePipe().transform(input);

here is the working example on JsFiddle

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72