Eduard Arevshatyan Eduard Arevshatyan - 1 year ago 62
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 = "";
public getListsServices(): Observable<Response> {
return this.http.get(this.baseURL + this.listsUrl);

And in one of column i get a date in this format
(this date i get from server).

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

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

Or what?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download