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.

deebs
  • 1,390
  • 10
  • 23
  • Perhaps you can better coerce the server to produce a decent format? http://stackoverflow.com/questions/4075683/sql-server-create-date – mplungjan Apr 11 '13 at 15:17
  • 1
    That's a .Net serialized date, here's how: http://stackoverflow.com/questions/1016847/converting-net-datetime-to-json – mattmanser Apr 11 '13 at 15:23
  • @mattmanser - that link helped. If I could mark your comment the answer, I would. Thank you – deebs Apr 11 '13 at 18:03
  • 1
    @deebs No problem, annoyingly SO converted the answer to a comment and I couldn't see how to undo it! – mattmanser Apr 12 '13 at 08:27

3 Answers3

1

I think this question and answers will help you: Convert a Unix timestamp to time in JavaScript

You just need to convert your timestamp.

Good luck.

Community
  • 1
  • 1
Odahviing
  • 90
  • 3
1

You will want to construct a Date() and use the getters to build up the format. https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date

For passing in a format, you will want to include your own library, here is one solution for generating it: http://blog.stevenlevithan.com/archives/date-time-format

Schleis
  • 41,516
  • 7
  • 68
  • 87
0

Thanks @mattmanser for this thread, which answered my question... Converting .NET DateTime to JSON

Solution:

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

I hate to 'answer my own question' but want to provide the solution to anyone else who may need it.

Community
  • 1
  • 1
deebs
  • 1,390
  • 10
  • 23