Dansmith12
Dansmith12

Reputation: 143

How to format a date string with ionic2

I'll make this concise. I have the following object:

obj = {date: 2017-04-05T17:48:20.084Z}

How do i format j.date ? I've tried the following code bellow but it does work

<ion-item *ngFor='let j of obj'>
    <ion-datetime displayFormat="MM/DD/YYYY">{{j.date}}</ion-datetime>
 </ion-item>

Upvotes: 1

Views: 2099

Answers (1)

gsc
gsc

Reputation: 1559

According to the docs, you shouldn’t place j.date inside the ion-datetime element, but you should bind to it using ngModel. The code:

<ion-item *ngFor='let j of obj'>
  <ion-datetime displayFormat="MM/DD/YYYY" [(ngModel)]="j.date"></ion-datetime>
</ion-item>

Upvotes: 2

Related Questions