0

There's a great thread here: How do I format a Microsoft JSON date? that shows how to parse an ASP.NET formatted JSON date:

/Date(1224043200000)/

... back into an actual JavaScript Date object. However, it doesn't show how to go the other way. So, given a date - how do I go from:

new Date() // to /Date(1224043200000)/ ???
Community
  • 1
  • 1
ConfusedNoob
  • 9,826
  • 14
  • 64
  • 85

2 Answers2

3
var d = ['/Date(', new Date().getTime(), ')/'].join('');
Bakudan
  • 19,134
  • 9
  • 53
  • 73
Andrey M.
  • 3,688
  • 3
  • 33
  • 36
2
var t = new Date();
t.getTime();
Bakudan
  • 19,134
  • 9
  • 53
  • 73
Cliff
  • 1,621
  • 1
  • 13
  • 22
  • Well, that gets you the number of milliseconds corresponding to the Date t. I suppose you can take that and wrap it in a `/Date(` `)/` string. – Robert Harvey Sep 30 '11 at 04:36