c# DateTime Javascript解析的回报C# DateTime to Javascript parse returns

- 此内容更新于:2015-01-06

aspx我得到 = /日期(1420460565000)/日期 我试图解析它的javascript bject日期 然而,当我运行它变得无效数据 我如何解析c# DateTime对象?


on the aspx I am getting

date = /Date(1420460565000)/

I tried to parse it javascript date bject

var dateformatted = new Date(date);

However when I run it I am getting Invalid Data

How do I parse the c# DateTime object?

RobG的回复:你应该使用的数字,例如像新的日期(+ date.replace(& # 47; d # 47;g & # 39;& # 39;))。

(原文:You should use just the numbers, e.g. something like new Date(+date.replace(/D/g,'')).)

Balanikas的回复:可能重复解析javascript datetime的c# datetime

(原文:possible duplicate of Parsing the C# datetime to javascript datetime)

Fedor的回复:可能重复的ASP。净MVC JsonResult日期格式

(原文:possible duplicate of ASP.NET MVC JsonResult Date Format)


(原文:Come on! This question was asked and answered must be hundred times. Use search, you are not novice here.)


(原文:@Fedor—then mark it as a dupe. ;-))

你可以试试这个: 这工作,因为字符串的子串函数/日期(“部分,parseInt功能得到整数,而忽略了“)/”。由此产生的号码是传递给构造函数。因此可以创建一个新的日期。

You could try this one:

var dateformatted = new Date(parseInt(date.substr(6)));

This works because substr function takes out the "/Date(" part, and the parseInt function gets the integer and ignores the ")/" at the end. The resulting number is passed into the Date constructor. Hence a new Date can be created.