问题描述
我没有找到一个很好的方式获得的DateTimeOffset值的JavaScript(angular2)。
我使用的WebAPI(5.2.3)和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 : "2016-03-08T17:27:11.9975483+01:00"
的JavaScript / angular2不承认这是有效的datetime值。
JavaScript/angular2 does not recognize this as valid datetime value.
我有选择,但我应该去什么方向:
I do have options, but what direction should I go:
- 服务器端:Newtonsoft.Json,...
- 客户端:angular2,...
- 其他?
许多thankx您的帮助!
Many thankx for your help!
推荐答案
Thankx到PierreDuc反馈,我已经打左右,我来到了以下结论:
Thankx to PierreDuc feedback I have played around and I came to the following conclusion:
由于JSON不支持日期
的数据类型,我想一个人做在客户端的转换。我用下面的'模式'(见):
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() {
return this.http.get('/api/tag/getAll')
.map((response: Response) => this.convertData(response));
}
private convertData(response: Response) {
var data = response.json() || [];
data.forEach((d) => {
// Convert to a Date datatype
d.RecordModifiedAt = new Date(d.RecordModifiedAt);
});
return data;
}
这篇关于ASP.NET的WebAPI的DateTimeOffset序列化到JSON / JavaScript的(angular2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!