ConfusedNoob
ConfusedNoob

Reputation: 10186

Creating an JSON Date a la ASP.NET Format

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)/ ???

Upvotes: 0

Views: 587

Answers (2)

Andrey M.
Andrey M.

Reputation: 3766

var d = ['/Date(', new Date().getTime(), ')/'].join('');

Upvotes: 3

Cliff
Cliff

Reputation: 1701

var t = new Date();
t.getTime();

Upvotes: 2

Related Questions