0

I'm still new to programming, and am having trouble converting this date. I'm using ajax with a chat application, and pull the date from SQL Server database record but can't seem to convert it. The line of code getting the date is simply:

var timeStart = results.d[i].CreateDate;

the result I get is: /Date(1365692153250)/

I tried adding 'new Date( )' before, and/or '.format(MMMM ...)' after. This is probably an easy one, but I've looked all over. Please let me know if any additional info is needed. Thanks.

4

3 回答 3

1

我认为这个问题和答案会对您有所帮助: Convert a Unix timestamp to time in JavaScript

你只需要转换你的时间戳。

祝你好运。

于 2013-04-11T15:16:02.173 回答
1

您将需要构造 aDate()并使用 getter 来构建格式。 https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date

对于传递格式,您需要包含自己的库,这是生成它的一种解决方案:http: //blog.stevenlevithan.com/archives/date-time-format

于 2013-04-11T15:16:12.420 回答
0

感谢@mattmanser 的这个线程,它回答了我的问题......将.NET DateTime 转换为 JSON

解决方案:

var timeStart = results.d[i].CreateDate.replace(/\/Date\((-?\d+)\)\//, '$1');
var d = new Date(parseInt(timeStart));

我讨厌“回答我自己的问题”,但想为可能需要它的其他人提供解决方案。

于 2013-04-18T15:46:27.643 回答