-2

have json

{"id":1,"name":"123","dateoff":"2016-01-12T13:30:46.358+05:00","available":true}

and have class

export class Compaing {
    constructor(public id: number, public name: string,
                public dateoff: Date, public available:boolean) { }
}

But when i use in angular2

<Compaing>res.json()

It dont work. In compaing.dateoff not date, it's string. How parse json string date to Date with constructor?

FireGM
  • 2,971
  • 2
  • 12
  • 10

1 Answers1

1

You could try something like this:

export class Compaing {
    dateoff:Date;
    constructor(public id: number, public name: string,
                public dateoffstr: string, public available:boolean)        {
       this.dateoff =new Date(dateoffstr);
    }
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Michael Desigaud
  • 2,115
  • 1
  • 15
  • 15