Skip to content Skip to sidebar Skip to footer

Asp.net Webapi Datetimeoffset Serialize To Json/javascript (angular2)

I do not find a nice way to get a DateTimeOffset value to JavaScript (angular2). I am using WebApi (5.2.3) and angular2. On the wire I see the date as follow: RecordModifiedAt :

Solution 1:

Thankx to PierreDuc feedback I have played around and I came to the following conclusion:

Since JSON does not support a Date datatype, I assume one has to make the conversion on the client side. I use the following 'pattern' (see http://codegur.com/36681078/angular-2-date-deserialization):

getTags() {
    returnthis.http.get('/api/tag/getAll')
        .map((response: Response) =>this.convertData(response));
}

privateconvertData(response: Response) {
    var data = response.json() || [];
    data.forEach((d) => {
        // Convert to a Date datatype
        d.RecordModifiedAt = newDate(d.RecordModifiedAt);
    });
    return data;
}

Post a Comment for "Asp.net Webapi Datetimeoffset Serialize To Json/javascript (angular2)"