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,366
  • 14
  • 56
  • 81

2 Answers2

3
var d = ['/Date(', new Date().getTime(), ')/'].join('');
Bakudan
  • 18,466
  • 9
  • 50
  • 71
Andrey M.
  • 3,568
  • 3
  • 30
  • 36
2
var t = new Date();
t.getTime();
Bakudan
  • 18,466
  • 9
  • 50
  • 71
Cliff
  • 1,531
  • 1
  • 12
  • 21
  • 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