Eduard Arevshatyan Eduard Arevshatyan - 1 month ago 5
TypeScript Question

Transforming name of date

I have application (table application) in Angular 2 with typescript. And i get some data from server with GET (http service):

private baseURL: string = "http://101.16.7.32/backend";
public getListsServices(): Observable<Response> {
return this.http.get(this.baseURL + this.listsUrl);
}


And in one of column i get a date in this format
2016-11-01T09:23:56.870189+03:00
(this date i get from server).

Now, my task is show only date -
2016-11-01
, and time dont using and showing.
What i should do? Create some custom
@Pipe
?
Like this:

@Pipe({ name: 'transformingDate' })
export class TransDate implements PipeTransform {
transform(value: boolean): string {
return (!!value) ? 'date' : 'false';
}
}


Or what?

Answer

You can simply use DatePipe:

<div>{{myDate | date: yMd}}</div>

Will output 2016/11/01 if myDate is 2016-11-01T09:23:56.870189+03:00 (that's an ISO string).

Check the documentation link if you want to customise of the output.

Comments