REST json Date property format

Thursday, June 16, 2016
Avatar
Hi, can anyone explain in what format Date properties are returned over REST Api? (e.g. "StartDate": "/Date(1078128000000-0800)/",)
2 Replies
Friday, June 17, 2016
Avatar
inflectra.jimx
re: Alchnemesis Thursday, June 16, 2016

Hi Predrag

SpiraTeam uses the WCF JSON serialization library from Microsoft .NET to convert dates into JSON. You can read more about this format here.

Basically, Dates in SpiraTeam are represented in JSON as "\/Date(number of ticks)\/".

The number of ticks is a positive or negative long value that indicates the number of ticks (milliseconds) that have elapsed since midnight 01 January, 1970 UTC.

Regards

Jim

Monday, October 19, 2020
Avatar
re: inflectra.jimx Friday, June 17, 2016

The JSON specification does not specify a format for exchanging dates which is why there are so many different ways to do it. The problem with dates in JSON and JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript/jQuery following Date constructor straight away converts the milliseconds since 1970 to Date as follows:
 
var jsonDate = new Date(1297246301973);

Then let's convert it to js format:

var date = new Date(parseInt(jsonDate.substr(6)));

The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor .

For ISO-8601 formatted JSON dates, just pass the string into the Date constructor:

var date = new Date(jsonDate);

 

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Thursday, June 16, 2016
  • Last Reply: Monday, October 19, 2020
  • Replies: 2
  • Views: 10787