How to pass a JSON date value via ASP.NET MVC usin

2020-02-18 05:13发布

Possible Duplicate:
Format a Microsoft JSON date?

The ASP.NET function Json() formats and returns a date as

{"d":"\/Date(1240718400000)\/"}

which has to be dealt with on the client side which is problematic. What are your suggestions for approaches to sending date values back and forth?

7条回答
相关推荐>>
2楼-- · 2020-02-18 06:00

It may be ugly, but it works:

 var epoch = (new RegExp('/Date\\((-?[0-9]+)\\)/')).exec(d);
 $("#field").text((new Date(parseInt(epoch[1]))).toDateString());

Probably, it is not necessary to match the whole string, and just (-?[0-9]+) is enough...

查看更多
登录 后发表回答